GeeCON Prague 2014*
The moose likes Spring and the fly likes form:options tag should display string instead of int Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "form:options tag should display string instead of int" Watch "form:options tag should display string instead of int" New topic
Author

form:options tag should display string instead of int

albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 245
I want to use the form:options provided by Spring to provide as choices in string instead of int.
e.g. display "Monthly", "Block" and "Per Use" as choices but save the choice in billingType as int.

My JSP implemented with Spring 2.5.6 is
[code] <td><form:select path="billingType">
<form:options items="${addAccountCommand.billingTypeChoice}"/>
</form:select>[/code]

(Note. The following is not implemented because running it in Eclipse will cause an Exception in thread "main" org.mozilla.javascript.EvaluatorException: syntax error (addAccount.jsp#17)
at org.mozilla.javascript.DefaultErrorReporter.runtim eError(DefaultErrorReporter.java:95)
at org.mozilla.javascript.DefaultErrorReporter.error( DefaultErrorReporter.java:82)
...
<td><form:select path="billingType">
<form:options items="${addAccountCommand.billingTypeChoice}" itemValue="billingType" itemLabel="billingTypeName" />
</form:select>
end Note)


My AccountCommand.java is
[code] private int billingType;
private String billingTypeName;

public int getBillingType() {
return billingType;
}

public void setBillingType(final int billingType) {
this.billingType = billingType;
}

public String getBillingTypeName() {
return billingTypeName;
}

public void setBillingTypeName(final String billingTypeName) {
this.billingTypeName = billingTypeName;
}

public Map<String, Integer> billingTypeChoice = new HashMap<String, Integer>() {
{
put("Monthly", 1);
put("Block", 2);
put("Per Use", 3);
}
};

public Map<String, Integer> getBillingTypeChoice() {
return billingTypeChoice;
}

public void setBillingTypeChoice(final Map<String, Integer> billingTypeChoice) {
this.billingTypeChoice = billingTypeChoice;
}
[/code]

My jsp page apppears with "1", "2" and "3" as options instead of "Monthly", "Block" and "Per Use".
Clicking the "Add" button cannot submit the form.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: form:options tag should display string instead of int