I want to create a dropdown field with all the US territories with Struts2, but the s:select property only allows for the inclusion of a few options. I have seen other tutorials create an action that maps to a list and then linking that action to the form but I am already using the form with another action. Ignore any other missing info, everything else works except I am not sure how to create a dropdown with all us territories given the element limit.
formPage.jsp:
<s:form action="submitForm"> <s:textfield name="firstName" label="First Name"/> <s:textfield name="lastName" label="Last Name"/> <s:select name="state" label="State" list="#{'CA':'California', 'NY':'New York', 'TX':'Texas'}" headerKey="" headerValue="-- Select State --" /> </s:form>`
inputForm.java:
public class inputForm extends ActionSupport{`
public String execute() {
return SUCCESS;
}
String firstName;
String lastName;
String state;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public void validate() {
if (getFirstName().length() == 0) {
addFieldError("salutation", "First name is required.");
}
if (getLastName().length() == 0) {
addFieldError("salutation", "Last name is required.");
}
if (getState().length() == 0) {
addFieldError("salutation", "State is required.");
}
}
}
struts.xml:
<action name="submitForm" class="Validation.verification.inputForm"> <result name="success">/WEB-INF/verification/results.jsp</result> <result name="input">/WEB-INF/verification/formPage.jsp</result> </action>