Anil,
There are a number of UI helper methods like this already in ExpressionUIHelper.java. -Adrian [hidden email] wrote: > Author: apatel > Date: Wed Jul 8 12:33:16 2009 > New Revision: 792113 > > URL: http://svn.apache.org/viewvc?rev=792113&view=rev > Log: > Added method to return List of month number and month name entries for the year. Will be useful for building dropdown lists. > > Modified: > ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java > > Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java > URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java?rev=792113&r1=792112&r2=792113&view=diff > ============================================================================== > --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java (original) > +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java Wed Jul 8 12:33:16 2009 > @@ -33,6 +33,8 @@ > import java.util.Map; > import java.util.TimeZone; > > +import javolution.util.FastMap; > + > /** > * Utility class for handling java.util.Date, the java.sql data/time classes and related > */ > @@ -955,6 +957,27 @@ > } > > /** > + * Returns a List of Maps of month number and name entries - suitable for select inputs. > + * > + * @param locale > + * @return List of month number, name > + */ > + public static List<Map<String,Object>> getMonths(Locale locale) { > + Calendar tempCal = Calendar.getInstance(locale); > + tempCal.set(Calendar.MONTH, Calendar.JANUARY); > + SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM", locale); > + List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>(); > + for (int i = Calendar.JANUARY; i <= tempCal.getActualMaximum(Calendar.MONTH); i++) { > + Map<String,Object> monthEntry = new FastMap<String,Object>(); > + monthEntry.put("monthNumber",tempCal.get(Calendar.MONTH)); > + monthEntry.put("monthName",dateFormat.format(tempCal.getTime())); > + resultList.add(monthEntry); > + tempCal.roll(Calendar.MONTH, 1); > + } > + return resultList; > + } > + > + /** > * Returns an initialized DateFormat object. > * > * @param dateFormat > > > |
Adrian,
I started to use ExpressionUIHelper.getMonthValueList() for populating months in form dropdown elements. We are facing problem when value returned by ExpressionUIHelper.getMonthValueList is given to Form widget dropdown element, {code} + <form name="MonthlyTrialBalance" type="single" target="MonthlyTrialBalance" title="Find list of monthly transaction totals" + header-row-style="header-row" default-table-style="basic- table"> + + <field name="organizationPartyId"><hidden/></field> + <field name="trialBalanceMonth" required-field="true"> + <drop-down> + <list-options list-name="monthList" key-name="value" description="${description}"/> + </drop-down> + </field> + <field name="isPosted"> + <drop-down> + <option description="${uiLabelMap.CommonYes}" key="Y"/> + <option description="${uiLabelMap.CommonNo}" key="N"/> + <option description="${uiLabelMap.CommonAll}" key="All"/> + </drop-down> + </field> + <field name="submitButton" widget-style="smallSubmit"><submit button-type="button"/></field> + </form> {code} we get following error {error} [component://common/widget/CommonScreens.xml#GlobalDecorator]: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Stringjava.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String (java.lang.Integer cannot be cast to java.lang.String) ---- cause --------------------------------------------------------------------- Exception: java.lang.ClassCastException Message: java.lang.Integer cannot be cast to java.lang.String ---- stack trace --------------------------------------------------------------- java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String org.ofbiz.widget.form.ModelFormField $ListOptions.addOptionValues(ModelFormField.java:1647) org.ofbiz.widget.form.ModelFormField $FieldInfoWithOptions.getAllOptionValues(ModelFormField.java:1525) org .ofbiz .widget .form.MacroFormRenderer.renderDropDownField(MacroFormRenderer.java:652) org.ofbiz.widget.form.ModelFormField $DropDownField.renderFieldString(ModelFormField.java:2954) org .ofbiz .widget.form.ModelFormField.renderFieldString(ModelFormField.java:592) org.ofbiz.widget.form.ModelForm.renderSingleFormString(ModelForm.java: 1028) org.ofbiz.widget.form.ModelForm.renderFormString(ModelForm.java:811) org.ofbiz.widget.screen.ModelScreenWidget $Form.renderWidgetString(ModelScreenWidget.java:828) org .ofbiz .widget .screen .ModelScreenWidget.renderSubWidgetsString(ModelScreenWidget.java:138) org.ofbiz.widget.screen.ModelScreenWidget $DecoratorSection.renderWidgetString(ModelScreenWidget.java:691) {error} We can resolve this error if we modify ExpressionUiHelper.java file at line 99 to following statement. {code} result.add(UtilMisc.toMap("description", dateFormat.format(tempCal.getTime()), "value", String.valueOf(i))); {code} If you don't mind I'll make this modification and then replace ftl (committed in r794667 ) with form widget code. Regards Anil Patel On Jul 8, 2009, at 8:37 PM, Adrian Crum wrote: > Anil, > > There are a number of UI helper methods like this already in > ExpressionUIHelper.java. > > -Adrian > > [hidden email] wrote: >> Author: apatel >> Date: Wed Jul 8 12:33:16 2009 >> New Revision: 792113 >> URL: http://svn.apache.org/viewvc?rev=792113&view=rev >> Log: >> Added method to return List of month number and month name entries >> for the year. Will be useful for building dropdown lists. >> Modified: >> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ >> UtilDateTime.java >> Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ >> UtilDateTime.java >> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java?rev=792113&r1=792112&r2=792113&view=diff >> = >> = >> = >> = >> = >> = >> = >> = >> = >> ===================================================================== >> --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ >> UtilDateTime.java (original) >> +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ >> UtilDateTime.java Wed Jul 8 12:33:16 2009 >> @@ -33,6 +33,8 @@ >> import java.util.Map; >> import java.util.TimeZone; >> +import javolution.util.FastMap; >> + >> /** >> * Utility class for handling java.util.Date, the java.sql data/ >> time classes and related >> */ >> @@ -955,6 +957,27 @@ >> } >> /** >> + * Returns a List of Maps of month number and name entries - >> suitable for select inputs. >> + * >> + * @param locale >> + * @return List of month number, name >> + */ >> + public static List<Map<String,Object>> getMonths(Locale >> locale) { >> + Calendar tempCal = Calendar.getInstance(locale); >> + tempCal.set(Calendar.MONTH, Calendar.JANUARY); >> + SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM", >> locale); >> + List<Map<String,Object>> resultList = new >> ArrayList<Map<String,Object>>(); >> + for (int i = Calendar.JANUARY; i <= >> tempCal.getActualMaximum(Calendar.MONTH); i++) { >> + Map<String,Object> monthEntry = new >> FastMap<String,Object>(); >> + >> monthEntry.put("monthNumber",tempCal.get(Calendar.MONTH)); >> + >> monthEntry.put("monthName",dateFormat.format(tempCal.getTime())); >> + resultList.add(monthEntry); >> + tempCal.roll(Calendar.MONTH, 1); >> + } >> + return resultList; >> + } >> + >> + /** >> * Returns an initialized DateFormat object. >> * >> * @param dateFormat |
The problem is in line 1647 of ModelFormField.java (which assumes the
key is a String). Any fixes should be done there. -Adrian Anil Patel wrote: > Adrian, > > I started to use ExpressionUIHelper.getMonthValueList() for populating > months in form dropdown elements. We are facing problem when value > returned by ExpressionUIHelper.getMonthValueList is given to Form widget > dropdown element, > > {code} > + <form name="MonthlyTrialBalance" type="single" > target="MonthlyTrialBalance" title="Find list of monthly transaction > totals" > + header-row-style="header-row" default-table-style="basic-table"> > + > + <field name="organizationPartyId"><hidden/></field> > + <field name="trialBalanceMonth" required-field="true"> > + <drop-down> > + <list-options list-name="monthList" key-name="value" > description="${description}"/> > + </drop-down> > + </field> > + <field name="isPosted"> > + <drop-down> > + <option description="${uiLabelMap.CommonYes}" key="Y"/> > + <option description="${uiLabelMap.CommonNo}" key="N"/> > + <option description="${uiLabelMap.CommonAll}" key="All"/> > + </drop-down> > + </field> > + <field name="submitButton" widget-style="smallSubmit"><submit > button-type="button"/></field> > + </form> > {code} > > we get following error > > {error} > > [component://common/widget/CommonScreens.xml#GlobalDecorator]: > java.lang.ClassCastException: java.lang.Integer cannot be cast to > java.lang.Stringjava.lang.ClassCastException: java.lang.Integer cannot > be cast to java.lang.String (java.lang.Integer cannot be cast to > java.lang.String) > ---- cause > --------------------------------------------------------------------- > Exception: java.lang.ClassCastException > Message: java.lang.Integer cannot be cast to java.lang.String > ---- stack trace > --------------------------------------------------------------- > java.lang.ClassCastException: java.lang.Integer cannot be cast to > java.lang.String > org.ofbiz.widget.form.ModelFormField$ListOptions.addOptionValues(ModelFormField.java:1647) > > org.ofbiz.widget.form.ModelFormField$FieldInfoWithOptions.getAllOptionValues(ModelFormField.java:1525) > > org.ofbiz.widget.form.MacroFormRenderer.renderDropDownField(MacroFormRenderer.java:652) > > org.ofbiz.widget.form.ModelFormField$DropDownField.renderFieldString(ModelFormField.java:2954) > > org.ofbiz.widget.form.ModelFormField.renderFieldString(ModelFormField.java:592) > > org.ofbiz.widget.form.ModelForm.renderSingleFormString(ModelForm.java:1028) > org.ofbiz.widget.form.ModelForm.renderFormString(ModelForm.java:811) > org.ofbiz.widget.screen.ModelScreenWidget$Form.renderWidgetString(ModelScreenWidget.java:828) > > org.ofbiz.widget.screen.ModelScreenWidget.renderSubWidgetsString(ModelScreenWidget.java:138) > > org.ofbiz.widget.screen.ModelScreenWidget$DecoratorSection.renderWidgetString(ModelScreenWidget.java:691) > > > {error} > > We can resolve this error if we modify ExpressionUiHelper.java file at > line 99 to following statement. > > {code} > result.add(UtilMisc.toMap("description", > dateFormat.format(tempCal.getTime()), "value", String.valueOf(i))); > {code} > > If you don't mind I'll make this modification and then replace ftl > (committed in r794667 ) with form widget code. > > Regards > Anil Patel > > On Jul 8, 2009, at 8:37 PM, Adrian Crum wrote: > >> Anil, >> >> There are a number of UI helper methods like this already in >> ExpressionUIHelper.java. >> >> -Adrian >> >> [hidden email] wrote: >>> Author: apatel >>> Date: Wed Jul 8 12:33:16 2009 >>> New Revision: 792113 >>> URL: http://svn.apache.org/viewvc?rev=792113&view=rev >>> Log: >>> Added method to return List of month number and month name entries >>> for the year. Will be useful for building dropdown lists. >>> Modified: >>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java >>> Modified: >>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java >>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java?rev=792113&r1=792112&r2=792113&view=diff >>> >>> ============================================================================== >>> >>> --- >>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java >>> (original) >>> +++ >>> ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilDateTime.java >>> Wed Jul 8 12:33:16 2009 >>> @@ -33,6 +33,8 @@ >>> import java.util.Map; >>> import java.util.TimeZone; >>> +import javolution.util.FastMap; >>> + >>> /** >>> * Utility class for handling java.util.Date, the java.sql data/time >>> classes and related >>> */ >>> @@ -955,6 +957,27 @@ >>> } >>> /** >>> + * Returns a List of Maps of month number and name entries - >>> suitable for select inputs. >>> + * >>> + * @param locale >>> + * @return List of month number, name >>> + */ >>> + public static List<Map<String,Object>> getMonths(Locale locale) { >>> + Calendar tempCal = Calendar.getInstance(locale); >>> + tempCal.set(Calendar.MONTH, Calendar.JANUARY); >>> + SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM", >>> locale); >>> + List<Map<String,Object>> resultList = new >>> ArrayList<Map<String,Object>>(); >>> + for (int i = Calendar.JANUARY; i <= >>> tempCal.getActualMaximum(Calendar.MONTH); i++) { >>> + Map<String,Object> monthEntry = new >>> FastMap<String,Object>(); >>> + monthEntry.put("monthNumber",tempCal.get(Calendar.MONTH)); >>> + >>> monthEntry.put("monthName",dateFormat.format(tempCal.getTime())); >>> + resultList.add(monthEntry); >>> + tempCal.roll(Calendar.MONTH, 1); >>> + } >>> + return resultList; >>> + } >>> + >>> + /** >>> * Returns an initialized DateFormat object. >>> * >>> * @param dateFormat > > |
Free forum by Nabble | Edit this page |