File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

form:options tag should display string instead of int

albert kao
Ranch Hand

Joined: Feb 04, 2010
Posts: 252
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}"/>

(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(
at org.mozilla.javascript.DefaultErrorReporter.error(
<td><form:select path="billingType">
<form:options items="${addAccountCommand.billingTypeChoice}" itemValue="billingType" itemLabel="billingTypeName" />
end Note)

My 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;

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:
subject: form:options tag should display string instead of int
jQuery in Action, 3rd edition