You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Fernando Jimenez <fe...@db.com> on 2003/04/17 18:05:19 UTC

Storing a collection in an actionform

Hi everyone

I'll go to the point. I have an actionform that takes in two String values. One of them is selected by the user with a drop down box, and the other one is a simple text field.

To display the selection box I'm storing the available options in a collection of beans in the action form as well. This collection is populated in the Action class associated with this form. I then retrieve the collection in the jsp with:

<bean:define id="options" name="myForm" property="options" type="java.util.Collection"/>

To display it in the jsp I then do this:

<html:select property="selectedOption">
        <html:options collection="options" property="value" labelProperty="label"/>
</html:select>

This is all very well, and it works perfectly. However, if the validate method in the form returns an error, because the form has been repopulated and the Action class is never called, the colleciton is lost. Therefore the user is presented with the same page, an error message at the top, and an empty drop down box.

I have had this problem in the past with other fields (simple text fields), but I haven't used selection boxes before. Therefore my trick was to enter these values as hidden fields using <html:hidden>, which worked fine. However, I can't think of any smart or clean way to get around this problem with a simmilar trick, so I turn to you guys.

What would be the best way to tackle this problem? Should I not be storing the options in the action form at all? what would you advise?

I thought of changing the scope of the action form to session rather than request, but I don't really want to do that. Otherwise, if the user comes back to the screen, he/she will see the last values that were entered, right?

Please help

Thanks a bunch in advance

FJ


--

This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Storing a collection in an actionform

Posted by Brandon Goodin <ma...@phase.ws>.
Validate in your action class. Upon failure repopulate the collection and
return to the input page.

Brandon Goodin

-----Original Message-----
From: Fernando Jimenez [mailto:fernando.jimenez@db.com]
Sent: Thursday, April 17, 2003 10:05 AM
To: struts-user@jakarta.apache.org
Subject: Storing a collection in an actionform


Hi everyone

I'll go to the point. I have an actionform that takes in two String values.
One of them is selected by the user with a drop down box, and the other one
is a simple text field.

To display the selection box I'm storing the available options in a
collection of beans in the action form as well. This collection is populated
in the Action class associated with this form. I then retrieve the
collection in the jsp with:

<bean:define id="options" name="myForm" property="options"
type="java.util.Collection"/>

To display it in the jsp I then do this:

<html:select property="selectedOption">
        <html:options collection="options" property="value"
labelProperty="label"/>
</html:select>

This is all very well, and it works perfectly. However, if the validate
method in the form returns an error, because the form has been repopulated
and the Action class is never called, the colleciton is lost. Therefore the
user is presented with the same page, an error message at the top, and an
empty drop down box.

I have had this problem in the past with other fields (simple text fields),
but I haven't used selection boxes before. Therefore my trick was to enter
these values as hidden fields using <html:hidden>, which worked fine.
However, I can't think of any smart or clean way to get around this problem
with a simmilar trick, so I turn to you guys.

What would be the best way to tackle this problem? Should I not be storing
the options in the action form at all? what would you advise?

I thought of changing the scope of the action form to session rather than
request, but I don't really want to do that. Otherwise, if the user comes
back to the screen, he/she will see the last values that were entered,
right?

Please help

Thanks a bunch in advance

FJ


--

This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org