Author: jacopoc
Date: Wed Jan 16 07:46:32 2008 New Revision: 612492 URL: http://svn.apache.org/viewvc?rev=612492&view=rev Log: Modified some of the form rendering method to output to a Writer instead of a StringBuffer: this will allow form widgets to be used to process large lists (not paginated). Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=612492&r1=612491&r2=612492&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Wed Jan 16 07:46:32 2008 @@ -18,6 +18,9 @@ *******************************************************************************/ package org.ofbiz.widget.form; +import java.io.IOException; +import java.io.Writer; + import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -674,7 +677,7 @@ * Renders this form to a String, i.e. in a text format, as defined with the * FormStringRenderer implementation. * - * @param buffer The StringBuffer that the form text will be written to + * @param writer The Writer that the form text will be written to * @param context Map containing the form context; the following are * reserved words in this context: parameters (Map), isError (Boolean), * itemIndex (Integer, for lists only, otherwise null), bshInterpreter, @@ -685,7 +688,7 @@ * different form elements; implementing your own makes it possible to * use the same form definitions for many types of form UIs */ - public void renderFormString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { + public void renderFormString(Writer writer, Map context, FormStringRenderer formStringRenderer) throws IOException { ModelFormAction.runSubActions(this.actions, context); setWidgetBoundaryComments(context); @@ -716,19 +719,20 @@ } if ("single".equals(this.type)) { - this.renderSingleFormString(buffer, context, formStringRenderer, positions); + this.renderSingleFormString(writer, context, formStringRenderer, positions); } else if ("list".equals(this.type)) { - this.renderListFormString(buffer, context, formStringRenderer, positions); + this.renderListFormString(writer, context, formStringRenderer, positions); } else if ("multi".equals(this.type)) { - this.renderMultiFormString(buffer, context, formStringRenderer, positions); + this.renderMultiFormString(writer, context, formStringRenderer, positions); } else if ("upload".equals(this.type)) { - this.renderSingleFormString(buffer, context, formStringRenderer, positions); + this.renderSingleFormString(writer, context, formStringRenderer, positions); } else { throw new IllegalArgumentException("The type " + this.getType() + " is not supported for form with name " + this.getName()); } } - public void renderSingleFormString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer, int positions) { + public void renderSingleFormString(Writer writer, Map context, FormStringRenderer formStringRenderer, int positions) throws IOException { + StringBuffer buffer = new StringBuffer(); List tempFieldList = FastList.newInstance(); tempFieldList.addAll(this.fieldList); @@ -959,9 +963,12 @@ // render form close if (!skipEnd) formStringRenderer.renderFormClose(buffer, context, this); + + writer.write(buffer.toString()); } - public void renderListFormString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer, int positions) { + public void renderListFormString(Writer writer, Map context, FormStringRenderer formStringRenderer, int positions) throws IOException { + StringBuffer buffer = new StringBuffer(); // render list/tabular type forms // prepare the items iterator and compute the pagination parameters @@ -976,14 +983,20 @@ numOfColumns = this.renderHeaderRow(buffer, context, formStringRenderer); } + writer.write(buffer.toString()); + buffer = new StringBuffer(); + // ===== render the item rows ===== - this.renderItemRows(buffer, context, formStringRenderer, true, numOfColumns); + this.renderItemRows(writer, context, formStringRenderer, true, numOfColumns); // render formatting wrapper close formStringRenderer.renderFormatListWrapperClose(buffer, context, this); + + writer.write(buffer.toString()); } - public void renderMultiFormString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer, int positions) { + public void renderMultiFormString(Writer writer, Map context, FormStringRenderer formStringRenderer, int positions) throws IOException { + StringBuffer buffer = new StringBuffer(); formStringRenderer.renderFormOpen(buffer, context, this); // render formatting wrapper open @@ -993,12 +1006,17 @@ // ===== render header row ===== numOfColumns = this.renderHeaderRow(buffer, context, formStringRenderer); + writer.write(buffer.toString()); + buffer = new StringBuffer(); + // ===== render the item rows ===== - this.renderItemRows(buffer, context, formStringRenderer, false, numOfColumns); + this.renderItemRows(writer, context, formStringRenderer, false, numOfColumns); formStringRenderer.renderFormatListWrapperClose(buffer, context, this); formStringRenderer.renderMultiFormClose(buffer, context, this); + + writer.write(buffer.toString()); } public int renderHeaderRow(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { @@ -1263,7 +1281,7 @@ } } - public void renderItemRows(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer, boolean formPerItem, int numOfColumns) { + public void renderItemRows(Writer writer, Map context, FormStringRenderer formStringRenderer, boolean formPerItem, int numOfColumns) throws IOException { this.rowCount = 0; String lookupName = this.getListName(); if (UtilValidate.isEmpty(lookupName)) { @@ -1457,7 +1475,9 @@ // are now rendered: this will create a visual representation // of one row (for the current position). if (innerDisplayHyperlinkFieldsBegin.size() > 0 || innerFormFields.size() > 0 || innerDisplayHyperlinkFieldsEnd.size() > 0) { + StringBuffer buffer = new StringBuffer(); this.renderItemRow(buffer, localContext, formStringRenderer, formPerItem, hiddenIgnoredFieldList, innerDisplayHyperlinkFieldsBegin, innerFormFields, innerDisplayHyperlinkFieldsEnd, currentPosition, numOfColumns); + writer.write(buffer.toString()); } } // iteration on positions } // iteration on items Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java?rev=612492&r1=612491&r2=612492&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormWrapper.java Wed Jan 16 07:46:32 2008 @@ -19,6 +19,7 @@ package org.ofbiz.widget.html; import java.io.IOException; +import java.io.StringWriter; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; @@ -101,7 +102,7 @@ } } - public String renderFormString(Object contextStack) { + public String renderFormString(Object contextStack) throws IOException { if (contextStack instanceof MapStack) { return renderFormString((MapStack) contextStack); } else { @@ -109,16 +110,16 @@ return renderFormString(); } } - public String renderFormString(MapStack contextStack) { + public String renderFormString(MapStack contextStack) throws IOException { // create a new context with the current context on the bottom contextStack.push(this.context); - StringBuffer buffer = new StringBuffer(); + StringWriter buffer = new StringWriter(); modelForm.renderFormString(buffer, contextStack, renderer); contextStack.pop(); return buffer.toString(); } - public String renderFormString() { - StringBuffer buffer = new StringBuffer(); + public String renderFormString() throws IOException { + StringWriter buffer = new StringWriter(); modelForm.renderFormString(buffer, context, renderer); return buffer.toString(); } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java?rev=612492&r1=612491&r2=612492&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Wed Jan 16 07:46:32 2008 @@ -638,10 +638,8 @@ } //Debug.logInfo("before renderFormString, context:" + context, module); - StringBuffer renderBuffer = new StringBuffer(); - modelForm.renderFormString(renderBuffer, context, formStringRenderer); try { - writer.write(renderBuffer.toString()); + modelForm.renderFormString(writer, context, formStringRenderer); } catch (IOException e) { String errMsg = "Error rendering included form named [" + name + "] at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); |
Free forum by Nabble | Edit this page |