This is a common and well documented idiom, but can be hard to
find in the archives ;)

The problem is that to display the form with the select list, you have
to prepare the select list before displaying the page.

When the user submits the form and validation fails, Struts will forward
to the input attribute value in the action mapping. If this value is the
.jsp instead of the action url which prepares the .jsp, you get the behavior you describe below.


One solution, is to assign the input attribute value to be the preparation action for the page.

Another solutions is to place your form in the session and override the
form reset() so that your customer list isn't wiped out when you submit
the request.

Another solution is if your customer list is unique to the user and doesn't change, populate the list and place it in the session when the user logs in and don't put it in the action form at all.

Another solution is if your customer list is static and global to all users, populate the customer list on application start up (ServletContextListener or Struts plugin) and place it in the ServletContext as an attribute.

hth,

/robert

Bernard Willemot wrote:
Hi,

Not sure it is the best practice...

I have a for to edit a user called UserForm. This form contains a popup
(<select>) with Customers.

I didnąt find an easier way to include the data of the popup in the
UserForm:

Public class UserForm extends ActionForm {
    ....
    protected ArrayList customer_popup;

    ....

public ArrayList getCustomerPopup() {
return this.customer_popup;
}
public void setCustomerPopup(ArrayList customer_popup) {
this.customer_popup = customer_popup;
}
}


So before editing the user and while building the form, I build the form and
fill the ArrayList with the customers as well.

So far so good that works, but if I use validation, and the page with the
form needs be reloading to tell me what went wrong, I have the problem that
struts doesnąt find the arraylist in the form anymore:

javax.servlet.ServletException: ServletException in
'/setup/users/edit_user_data.jsp': Failed to obtain specified collection

In the jsp, I use:

<html:select property='customerId'>
       <html:optionsCollection property='customerPopup' label='name'
value='id' />
</html:select>

If I remove it, it works fine.


Using struts 1.2.4 with TC 5.5.

Any idea?

Thank you, BW.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to