I have done this.  The reason the contents of the <select> boxes
aren't saved when you come back is that all of the <options> aren't
sent to the server, only the selected one is.

I use one <html:hidden /> field for every element of each select
box.  When the form loads, I populate the <select> boxes with
JavaScript by reading the hidden fields.  Then, when the user
moves something from one <select> to the other, I write that change
to the hidden fields with JavaScript.  Then, when the form is
submitted, the current state is stored in hidden fields, and will
be properly restored when Struts returns you to the form again.
It requires some interesting JavaScript to move things around
as they should be, and enough placeholder hidden fields
to contain all possible options from either select box.

The other alternative would be to use <html:select multiple="true" />,
and then use an onSubmit() JavaScript method to select all of
the options in both select boxes.  Then, all elements of the select
boxes will be sent to the server, and should be maintained by
Struts.  This would be simpler than the earlier suggestion, but,
it won't work if you don't want to set multiple="true".

Good luck,

Doug



                                                                                       
        
                    Vinay Cerejo                                                       
        
                    <vinay.cerejo@xo       To:     "'[EMAIL PROTECTED]'"  
        
                    riant.com>              <[EMAIL PROTECTED]>           
        
                                           cc:                                         
        
                    09/06/2001 01:41       Subject:     Mainatinig Select list state   
        
                    AM                                                                 
        
                    Please respond                                                     
        
                    to struts-user                                                     
        
                                                                                       
        
                                                                                       
        




HI,
 I have two select lists, one filled with data and the other empty
Lets call the filled list as AllElements
and the empty list as UserElements

AllElements                    UserElements
 ------------------              -------------------
| element1    |                   |                         |
| element2    |       >> |                        |
| element3    |            |                      |
| element4    |      <<  |                        |
-------------------             --------------------

The user selects items from AllElements and moves them to UserElements
and then submits the form.

Now when any validation error in the Form bean. i throw the user back to
the
same form

But my user selections have been lost. How do i maintain these.

Ofcourse i can maintain it by doing some coding to retreive all elements
again from the database
and using the request attributes and filtereing the selected ones etc,
but is there no support from struts for maintaing state in such scenario??

many Thanks,
Vinay






Reply via email to