struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: DynaValidatorForm - cannot find bean
Date Sun, 17 Dec 2006 21:38:25 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Philippe,

Pille wrote:
> but after submitting the form with wrong input and returning
> to the jsp-page i get the following exception:
> javax.servlet.jsp.JspException: Cannot find bean under name countries at
> org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:374)
> 
> after submitting the form with wrong parameters and returning to the
> page the beans are gone. is there any possibility to set the beans with
> request.setAttribute() again?

You are encountering a common problem with a simple solution. In order
to display the form the first time, you are loading "extra" data such as
the list of countries. When validation fails, Struts will send you back
to the "input" page to try again. If your "input" page is just your
form, you will be missing that "extra" information.

What I usually do is create two actions: one that loads the information
to be edited (the actual content of the form) and another to "prepare"
the display. This "prepare" action loads this "extra" information such
as a country list.

So, I'd have something like this:

<action path="/edit" type="EditAction" name="MyFormBean">
    <forward name="success" path="/prepare.do" />
</action>
<action path="/prepare" type="LoadExtraInfoAction" name="MyFormBean">
    <forward name="success" path="/edit.jsp" />
</action>
<action path="/save" type="SaveAction" name="MyFormBean"
        validate="true" input="/prepare.do">
    <forward name="success" ... />
</action>

As you can see, the "input" for SaveAction is now set to the "prepare"
action which loads that extra information, so it's available for the
form in case any validation errors occur.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFhbjQ9CaO5/Lv0PARAvi/AJ9hUMlxXYNg2DPT2e6dmRs9vzZ4JgCeNz5F
f82DadCFnxx7VpV5TwySH50=
=jad5
-----END PGP SIGNATURE-----

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


Mime
View raw message