use of org.apache.ofbiz.widget.model.ModelGrid in project ofbiz-framework by apache.
the class FormRenderer method render.
/**
* Renders this form to a writer, as defined with the
* FormStringRenderer implementation.
*
* @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), formName
* (String, optional alternate name for form, defaults to the
* value of the name attribute)
*/
public void render(Appendable writer, Map<String, Object> context) throws Exception {
// increment the paginator, only for list and multi forms
if (modelForm instanceof ModelGrid) {
WidgetWorker.incrementPaginatorNumber(context);
}
// Populate the viewSize and viewIndex so they are available for use during form actions
context.put("viewIndex", Paginator.getViewIndex(modelForm, context));
context.put("viewSize", Paginator.getViewSize(modelForm, context));
modelForm.runFormActions(context);
// if this is a list form, don't use Request Parameters
if (modelForm instanceof ModelGrid) {
context.put("useRequestParameters", Boolean.FALSE);
}
// find the highest position number to get the max positions used
int positions = 1;
for (ModelFormField modelFormField : modelForm.getFieldList()) {
int curPos = modelFormField.getPosition();
if (curPos > positions) {
positions = curPos;
}
FieldInfo currentFieldInfo = modelFormField.getFieldInfo();
if (currentFieldInfo == null) {
throw new IllegalArgumentException("Error rendering form, a field has no FieldInfo, ie no sub-element for the type of field for field named: " + modelFormField.getName());
}
}
if ("single".equals(modelForm.getType())) {
this.renderSingleFormString(writer, context, positions);
} else if ("list".equals(modelForm.getType())) {
this.renderListFormString(writer, context, positions);
} else if ("multi".equals(modelForm.getType())) {
this.renderMultiFormString(writer, context, positions);
} else if ("upload".equals(modelForm.getType())) {
this.renderSingleFormString(writer, context, positions);
} else {
if (UtilValidate.isEmpty(modelForm.getType())) {
throw new IllegalArgumentException("The form 'type' tag is missing or empty on the form with the name " + modelForm.getName());
}
throw new IllegalArgumentException("The form type " + modelForm.getType() + " is not supported for form with name " + modelForm.getName());
}
}
Aggregations