I finally resolved it--
Here is the solution--
The
struts-config.xml file--
The Action-form was created using SelectedItem as one more property for using it in the jsp file.
The Collections element was induced in the request object as CountryList.
The Action-Form
The Action - Class
The show-Details.jsp file--
What I observed was this--
For this to work in the form-bean if you have a country-list
countryList.add(new CountryData("1", "USA"));
countryList.add(new CountryData("2", "Canada"));
countryList.add(new CountryData("3", "Mexico"));
request.setAttribute("countryListAttribute",countryList);
Now, since the attribute in the request is set to countryListAttribute,
At the JSP side, for the html:select code,
<html:form action="/login">
<html:select name="UserDetailsForm" property="selectedItem">
<!-- property refers to the name of the request parameter in the form -->
<html:optionsCollection name="countryListAttribute" />
<!-- label="countryName" value="countryId" -->
</html:select>
<html:submit/>
</html:form>
Here , the action pertains to any action that will get executed once the submit is clicked.
The property=”selectedItem refers to a
string property in the form “UserDetailsForm ” which has been mapped in the struts-config.xml as a form-bean mapping.The name of the form-bean is “UserDetailsForm”. Now, with the name=”countryListAttribute” , it is taken from the request scope. The request scope is present in the action mapping as described as under.
Thus an important part to be noted is that in html:select , the property=”selectedItem” should be a string in the form-bean.
If you do not have getlabel() and getValue() to the associated form-bean then, by default, if you do not put label=”countryName” and value=”countryID” , it searches for the implementation of the getLabel() and getValue() inside the form-bean.