This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I've some problems with my select tags when validation fails.
For a registration, a user can select his birth city with a select tag. If the validation of the registration fails (empty or incorrect fields), i display the same jsp with errors messages.
In my case, when the validation fails, the list of cities contains only the selected element before the validation. And I don't understand why !!
My select is representing by a ArrayList in my action class (field 'ville') :
My registration jsp :
Note that I use the struts validation system with XML file ( <ClassAction>-<Aliasction>-validation.xml).
You have both the "list" and "value" attributes set to the same thing, so on return from validation the select's options will be set to the value of the action property. Normally the "list" contains the complete list of options and the "value" contains options for pre-selection.
Joined: Mar 08, 2009
Thanks David for your reply,
If i understand, i had to write :
And the selected value is set to 'civiliteSelected' ??
I try this case but it doesn't work... 'civiliteSelected' (and also 'civilites') has null value. (both the 'civiliteSelected' and the 'civilites' fields are declared as a String in my class name).
Note that i have correct getters and setters.
I think i don't understand very well the select's behavior...
I suspect you're doing something only minorly wrong; the JSP and action below work as expected (this uses the Convention plugin, but would be no different under standard config).
The pre-select value of civiliteSelected is reflected in the form, with the corresponding option element marked as selected, and civilites is set on form submission to the selected value. (Excuse any minor typos; did some manual editing.)
Joined: Mar 08, 2009
Great, it works fine !!
Now, I understand better the tag's behavior.
I misunderstood the 'value', 'name' and 'list' attributes. Now, it's good !