Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

form:options tag should display string instead of int

 
albert kao
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic