aspose file tools*
The moose likes Struts and the fly likes <s:select> and fail validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "<s:select> and fail validation" Watch "<s:select> and fail validation" New topic
Author

<s:select> and fail validation

Jonathan Poirier
Greenhorn

Joined: Mar 08, 2009
Posts: 3
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 08, 2009
Posts: 3
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Mar 08, 2009
Posts: 3
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

Joined: Sep 29, 2008
Posts: 12617

Every day's a week day for me some months ;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <s:select> and fail validation