• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

<s:select> and fail validation

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Every day's a week day for me some months ;)
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic