This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<s:select> and fail validation

 
Jonathan Poirier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !

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 :


Struts.xml :


Note that I use the struts validation system with XML file ( <ClassAction>-<Aliasction>-validation.xml).

I hope you can help me !! ;)

Regards,
Jonathan.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jonathan Poirier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Jonathan Poirier
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great, it works fine !!

Now, I understand better the tag's behavior.
I misunderstood the 'value', 'name' and 'list' attributes. Now, it's good !

Thanks a lot !! (And specially a Sunday ! ;) ).

Regards,
Jonathan.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every day's a week day for me some months ;)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic