Author: jonesde
Date: Thu Mar 8 23:03:06 2007 New Revision: 516317 URL: http://svn.apache.org/viewvc?view=rev&rev=516317 Log: Made check type field more useful with the options thingy underneath it; this may/will break old usage, if it ever was used... Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?view=diff&rev=516317&r1=516316&r2=516317 ============================================================================== --- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original) +++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Thu Mar 8 23:03:06 2007 @@ -409,8 +409,25 @@ </xs:attributeGroup> <!-- ================== FIELD TYPES ==================== --> <xs:element name="check" substitutionGroup="AllFields"> - <xs:complexType/> + <xs:complexType> + <xs:choice minOccurs="0" maxOccurs="unbounded"> + <xs:element ref="entity-options"/> + <xs:element ref="list-options"/> + <xs:element ref="option"/> + </xs:choice> + <xs:attributeGroup ref="attlist.check"/> + </xs:complexType> </xs:element> + <xs:attributeGroup name="attlist.check"> + <xs:attribute name="all-checked"> + <xs:simpleType> + <xs:restriction base="xs:token"> + <xs:enumeration value="true"/> + <xs:enumeration value="false"/> + </xs:restriction> + </xs:simpleType> + </xs:attribute> + </xs:attributeGroup> <xs:element name="date-find" substitutionGroup="AllFields"> <xs:complexType> <xs:attributeGroup ref="attlist.date-find"/> Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?view=diff&rev=516317&r1=516316&r2=516317 ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java Thu Mar 8 23:03:06 2007 @@ -2571,8 +2571,9 @@ } } - public static class CheckField extends FieldInfo { + public static class CheckField extends FieldInfoWithOptions { public final static String ROW_SUBMIT_FIELD_NAME = "_rowSubmit"; + protected FlexibleStringExpander allChecked = null; protected CheckField() { super(); @@ -2588,10 +2589,20 @@ public CheckField(Element element, ModelFormField modelFormField) { super(element, modelFormField); + allChecked = new FlexibleStringExpander(element.getAttribute("all-checked")); } public void renderFieldString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) { formStringRenderer.renderCheckField(buffer, context, this); + } + + public Boolean isAllChecked(Map context) { + String allCheckedStr = this.allChecked.expandString(context); + if (UtilValidate.isNotEmpty(allCheckedStr)) { + return new Boolean("true".equals(allCheckedStr)); + } else { + return null; + } } } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java?view=diff&rev=516317&r1=516316&r2=516317 ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/html/HtmlFormRenderer.java Thu Mar 8 23:03:06 2007 @@ -684,25 +684,54 @@ * @see org.ofbiz.widget.form.FormStringRenderer#renderCheckField(java.lang.StringBuffer, java.util.Map, org.ofbiz.widget.form.ModelFormField.CheckField) */ public void renderCheckField(StringBuffer buffer, Map context, CheckField checkField) { - // well, I don't know if this will be very useful... but here it is - ModelFormField modelFormField = checkField.getModelFormField(); - // never used: ModelForm modelForm = modelFormField.getModelForm(); + ModelForm modelForm = modelFormField.getModelForm(); String currentValue = modelFormField.getEntry(context); + Boolean allChecked = checkField.isAllChecked(context); - buffer.append("<input type=\"checkbox\""); + List allOptionValues = checkField.getAllOptionValues(context, modelForm.getDelegator()); + String event = modelFormField.getEvent(); + String action = modelFormField.getAction(context); + + // list out all options according to the option list + Iterator optionValueIter = allOptionValues.iterator(); + while (optionValueIter.hasNext()) { + ModelFormField.OptionValue optionValue = (ModelFormField.OptionValue) optionValueIter.next(); + + buffer.append("<div"); + + appendClassNames(buffer, context, modelFormField); + + buffer.append("><input type=\"checkbox\""); + + // if current value should be selected in the list, select it + if (Boolean.TRUE.equals(allChecked)) { + buffer.append(" checked=\"checked\""); + } else if (Boolean.FALSE.equals(allChecked)) { + // do nothing + } else if (UtilValidate.isNotEmpty(currentValue) && currentValue.equals(optionValue.getKey())) { + buffer.append(" checked=\"checked\""); + } + buffer.append(" name=\""); + buffer.append(modelFormField.getParameterName(context)); + buffer.append('"'); + buffer.append(" value=\""); + buffer.append(optionValue.getKey()); + buffer.append("\""); - appendClassNames(buffer, context, modelFormField); + if (UtilValidate.isNotEmpty(event) && UtilValidate.isNotEmpty(action)) { + buffer.append(" "); + buffer.append(event); + buffer.append("=\""); + buffer.append(action); + buffer.append('"'); + } + + buffer.append("/>"); - // if current value should be selected in the list, select it - if ("Y".equals(currentValue) || "T".equals(currentValue)) { - buffer.append(" checked=\"checked\""); + buffer.append(optionValue.getDescription()); + buffer.append("</div>"); } - buffer.append(" name=\""); - buffer.append(modelFormField.getParameterName(context)); - buffer.append('"'); - buffer.append(" value=\"Y\"/>"); - // any description by it? this.appendTooltip(buffer, context, modelFormField); |
Free forum by Nabble | Edit this page |