• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loosing changes in html:select

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys/gals,

I'm trying to populate a multi-selection html:select list in Struts. It works fine except for one thing. If I change the selection and try to submit and have the form validation fail, I loose any changes within the list. All other fields on the form are saved correctly.

This is the code I'm using.


I don't have a reset method in the form (although I initialize the array containing the selected values to a zero-length array in the declaration) and it doesn't get touched in the validate method. The only methods that influence the value for the array are its getter and setter.

Does anyone have any idea how to fix this?

Thanks
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first thing I'd do to debug this is put a System.out.println inside the setUsers() method on the form bean to see whether it's being called or not. If it is being called, there's something funny going on in your form bean. If it's not getting called, check the spelling to make sure the property name in the jsp matches the setter name on the form bean.

If these approches don't work, show us:
-The relevant portions of the form bean
-The relevant portions of struts-config.xml
-The jsp <html:form> tag.
 
Adam Kreiss
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help. The problem was with the struts config file.

It turned out that I was forwarding back to the initialization action for the page when validation failed. The list was the only field that I was loading from a database on that page so it was getting reinitialized everytime validation failed.
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question regarding this approach. If an action fwd is used as the "input" value of an action in the case of an error,(i.e., when a form validation fails, fwd to a someActionClass.do instead of somepage.jsp) when struts forwards to this new action, how do you get a handle on the ActionErrors object created upon the form validation method call?
 
Kim Kantola
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Just found the answer to my question, looks like struts puts the ActionErrors into the request, so a call to servletRequest.getAttribute("org.apache.struts.action.ERROR");
will return the ActionErrors object.
 
reply
    Bookmark Topic Watch Topic
  • New Topic