What you're doing is just fine. You just need to move your list
population code somewhere else so that it will always fire, even if
validation fails. You can do that in one of two ways that I know of.
1. Lazy initialization in your getter. E.g.:
private List<Thing> things;
public List<Thing> getThings() {
if (things == null) {
things = loadThings();
}
return things;
}
2. Use a @Before method to populate the list before validation runs.
The advantage to this approach is that if you have certain events
that fire that do not need to populate the list, then you can
disable list population for those events easily. E.g.:
private List<Thing> things;
public List<Thing> getThings() { return things; }
@Before(stages=LifecycleStage.BindingAndValidation, on={"!cancel"})
public void loadThings() {
// do whatever you need to do
}
The first option is more straightforward (IHMO), and the second is more
flexible. Either one should fix your problem.
-Ben
Asleson, Ryan wrote:
Hello,
I'm using Stripes 1.5 Beta on Java 6.
The general pattern I've been following in the application is that
every ActionBean has a view() method which is annotated with the
@DefaultHandler annotation, and the view() method is responsible for
populating the ActionBean with anything needed to display the page.
Usually the view() method has to grab some data from the database for
the page to be displayed.
This has worked well so far but I've run into a problem. I have a
page that has a few text boxes and a drop-down select box. The List
that populates the select box is retrieved from the database by the
view() method. When a @Validation fails, the text boxes are populated
correctly (with the information, right or wrong, that the user
entered) but the select box is empty and has no options -- obviously
the view() method did not have chance to repopulate the list on the
ActionBean.
How do I get around this? In the old Struts 1.x world (blah), a Tiles
controller backed every JSP and was responsible for populating the
page with info from a database.
Is my pattern of having every ActionBean with a view() method a poor
pattern?
I'm wondering if the <stripes:useActionBean> tag is what I need to
use, but I'm not sure how I should fit everything together.
Thanks!!
-Ryan
This e-mail message is being sent solely for use by the intended
recipient(s) and may contain confidential information. Any
unauthorized review, use, disclosure or distribution is prohibited. If
you are not the intended recipient, please contact the sender by phone
or reply by e-mail, delete the original message and destroy all
copies. Thank you.
------------------------------------------------------------------------
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
------------------------------------------------------------------------
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users