Reputation: 4829
I have simple user registration form. In which i am puting city as a tag. Here drop down box value coming from city master table from mysql database.
But when i storing whole user registration values, i m not be able to fetch currently selected city value. Can anyone help me...? My user registration form contains :
<s:form action="UserAction" >
<s:textfield name="name" label="User Name" />
<s:textfield name="age" label="Age" />
<s:radio name="sex" label="Sex" list="{'M','F'}" />
<s:select list="cities" key="cities.name" listValue="name">
</s:select>
<s:submit />
</s:form>
Upvotes: 1
Views: 21252
Reputation: 101
In your action class you are probably have an attribute based on the select tag. When you set this value add an annotation above the method signature.
Something like:
@RequiredStringValidator(type = ValidatorType.SIMPLE, message = "Please select a value", fieldName = "select")
This should sort you out. This can also be done within the struts.xml file in a fairly similar way.
Cheers Nathan
Upvotes: 0
Reputation: 4829
Finally got the solution after writing following code :
<s:select list="cities" name="city">
<s:iterator value="cities">
</s:iterator>
</s:select>
And at the time of insertion through DAO, it will automatically fetching all the value from bean.
Upvotes: 1
Reputation: 39907
Give your list the exact name what you have in your bean, in your case city. It should start working now.
Upvotes: 1