You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pille <al...@flipsonline.de> on 2006/12/17 21:00:53 UTC

DynaValidatorForm - cannot find bean

hi,
i have a DynaValidatorForm and a jsp-page to display the form data. in
the jsp page i´m using some combo boxes too.
i have one action class for all actions. this action class does all the
actions for this single jsp page and it extends MappingDispatchAction class.
to initialize my combo boxes with values i´m using e.g.
request.setAttribute("countries", countryNames) where countryNames is an
array of Strings. this works fine.

before i had a DynaActionForm where i havn´t done any validation. i
changed to DynaValidatorForm and added the appropriate settings in
struts-config.xml, validator.xml and MessageResources.properties.
then i wanted to test the validation. it works fine and i get the error
messages. 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?
thank you

greetz
philippe

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


Re: DynaValidatorForm - cannot find bean

Posted by Pille <al...@flipsonline.de>.

Christopher Schultz wrote:
> Philippe,
> 
> Pille wrote:
>>>> how can i set a property of a dyna form from within an action?
>>> That's easy: just do the same thing you do in your SaveAction to get a
>>> reference to the form bean. Then, instead of just calling accessors to
>>> get the data our, call mutators to put data in. But, if you are talking
>>> about accepting data from the form for re-display, why not just make it
>>> part of the form and have Struts do that work for you?
>> can you get more in detail please? ;)
> 
> I'm suggesting that, instead of writing code in your action to call
> request.getParameter("myFormStuff") and then poking it into the
> DynaValidatorBean, you add the appropriate fields to your dynamic bean
> (in struts-config.xml) so that Struts will populate (and validate!) your
> form bean for you.
> 
>>> Whenever I need parameters to be forwarded across multiple actions, I
>>> either put them in the form bean or do it manually by using hidden form
>>> elements, pulling their values out in my submission handling actions,
>>> and then put them back into the URLs of my redirect actions.
>> i had the ArrayList as property of a DynaActionForm. when i submitted
>> the form the Bean wasn´t set anymore.
> 
> How were you trying to submit the data that was supposed to go into that
> arraylist? Typically, one uses a special syntax for submitting indexed
> information by using form field names such as "salary[1]" -- not the use
> of the square-brackets and an explicit numeric index.

i iterate over the arraylist in a c:forEach loop. there i set the
properties of the arraylist like this:

<c:forEach var="currentp" items="${buyOnlineForm.chosenProducts}"
varStatus="itemStatus">

         <html:select name="currentp" property="product" indexed="true"
style='width: 100px;'>
	   <html:options name="currentp" property="productSelectionOptions"/>
	 </html:select>
....
</c:forEach>

where chosenProducts is an array list with beans. the bean has the
property product. you can see that the html:select tag is indexed. so i
can iterate dynamically with regexp over all the parameters passed on
submit.



> 
>> but there is another thing i´ve been thinking of. earlier i had my own
>> DynaActionForm class and i have set some properties in the
>> struts-config.xml. the ArrayList (which holds the beans) was set as a
>> property in my own class because i didn´t know how to access the getters
>> and setters of a DynaActionForm. the form tag in struts-config.xml was a
>> type of my own DynaActionForm extension. Is it ok to mix it like this or
>> do i either have to implement every property in a own DynaActionForm
>> class or do i have to declare everything in struts-config?

sorry, i meant "implement in a ActionForm class".

> 
> I would recommend that, if you are going to use DynaValidatorForm, you
> just use it as-is instead of subclassing it.

ok.

> 
> -chris

thank you

philippe

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



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


Re: DynaValidatorForm - cannot find bean

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Philippe,

Pille wrote:
>>> how can i set a property of a dyna form from within an action?
>>
>> That's easy: just do the same thing you do in your SaveAction to get a
>> reference to the form bean. Then, instead of just calling accessors to
>> get the data our, call mutators to put data in. But, if you are talking
>> about accepting data from the form for re-display, why not just make it
>> part of the form and have Struts do that work for you?
> 
> can you get more in detail please? ;)

I'm suggesting that, instead of writing code in your action to call
request.getParameter("myFormStuff") and then poking it into the
DynaValidatorBean, you add the appropriate fields to your dynamic bean
(in struts-config.xml) so that Struts will populate (and validate!) your
form bean for you.

>> Whenever I need parameters to be forwarded across multiple actions, I
>> either put them in the form bean or do it manually by using hidden form
>> elements, pulling their values out in my submission handling actions,
>> and then put them back into the URLs of my redirect actions.
> 
> i had the ArrayList as property of a DynaActionForm. when i submitted
> the form the Bean wasn´t set anymore.

How were you trying to submit the data that was supposed to go into that
arraylist? Typically, one uses a special syntax for submitting indexed
information by using form field names such as "salary[1]" -- not the use
of the square-brackets and an explicit numeric index.

> but there is another thing i´ve been thinking of. earlier i had my own
> DynaActionForm class and i have set some properties in the
> struts-config.xml. the ArrayList (which holds the beans) was set as a
> property in my own class because i didn´t know how to access the getters
> and setters of a DynaActionForm. the form tag in struts-config.xml was a
> type of my own DynaActionForm extension. Is it ok to mix it like this or
> do i either have to implement every property in a own DynaActionForm
> class or do i have to declare everything in struts-config?

I would recommend that, if you are going to use DynaValidatorForm, you
just use it as-is instead of subclassing it.

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

iD8DBQFFht4J9CaO5/Lv0PARAjKvAJ9ujuHgqP56RNsU+uwSwyl0umbmSgCgj2uq
UilHV6I9Sdlo6/e4uuDJQYQ=
=Hmsw
-----END PGP SIGNATURE-----

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


Re: DynaValidatorForm - cannot find bean

Posted by Pille <al...@flipsonline.de>.
Christopher Schultz wrote:
> Philippe,
> 
> Pille wrote:
>> how can i set a property of the form, that is used and needed in the jsp
>> of the form after editing?
> 
> I usually add that property to the form bean itself and then use a
> hidden parameter. For instance, if I'm editing a database record, I
> typically do this with the primary key of the record:
> 
> <input type="hidden" name="id" value="myBean.id" />
> 
>> how can i set a property of a dyna form from within an action?
> 
> That's easy: just do the same thing you do in your SaveAction to get a
> reference to the form bean. Then, instead of just calling accessors to
> get the data our, call mutators to put data in. But, if you are talking
> about accepting data from the form for re-display, why not just make it
> part of the form and have Struts do that work for you?

can you get more in detail please? ;)

> 
>> how do i
>> make sure that this property will be still set after submission and
>> redirecting over 2 sites?
> 
> Whenever I need parameters to be forwarded across multiple actions, I
> either put them in the form bean or do it manually by using hidden form
> elements, pulling their values out in my submission handling actions,
> and then put them back into the URLs of my redirect actions.

i had the ArrayList as property of a DynaActionForm. when i submitted
the form the Bean wasn´t set anymore.
but there is another thing i´ve been thinking of. earlier i had my own
DynaActionForm class and i have set some properties in the
struts-config.xml. the ArrayList (which holds the beans) was set as a
property in my own class because i didn´t know how to access the getters
and setters of a DynaActionForm. the form tag in struts-config.xml was a
type of my own DynaActionForm extension. Is it ok to mix it like this or
do i either have to implement every property in a own DynaActionForm
class or do i have to declare everything in struts-config?

> 
>> the problem is that i have 4 dynamic combo boxes and i always need to
>> iterate over the request parameters with a Regexp to get and reset all
>> the parameters of the combo boxes. the contents of the 4 combo boxes
>> depend on the previously made selection.
> 
> I rarely do this, but others have been talking about this lately. Look
> for messages that discuss "indexed" properties, which I think is what
> you need.

yes. i´m doing it like this too. in the jsp i´m using a c:forEach loop
to iterate over the ArrayList and display the values like this:

<html:select name="currentp" property="product" indexed="true">
...

> 
>> difficult to explain, sorry, hope you understand.
> 
> These kinds of things typically /are/ difficult to explain. Check the
> archives for the past couple of weeks to see if there's something there
> of any help. If not, post a new question to the list and include as much
> detail as possible (examples are usually the quickest way to do that).
> 
> Hope that helps,
> -chris
> 

thank you

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



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


Re: DynaValidatorForm - cannot find bean

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Philippe,

Pille wrote:
> how can i set a property of the form, that is used and needed in the jsp
> of the form after editing?

I usually add that property to the form bean itself and then use a
hidden parameter. For instance, if I'm editing a database record, I
typically do this with the primary key of the record:

<input type="hidden" name="id" value="myBean.id" />

> how can i set a property of a dyna form from within an action?

That's easy: just do the same thing you do in your SaveAction to get a
reference to the form bean. Then, instead of just calling accessors to
get the data our, call mutators to put data in. But, if you are talking
about accepting data from the form for re-display, why not just make it
part of the form and have Struts do that work for you?

> how do i
> make sure that this property will be still set after submission and
> redirecting over 2 sites?

Whenever I need parameters to be forwarded across multiple actions, I
either put them in the form bean or do it manually by using hidden form
elements, pulling their values out in my submission handling actions,
and then put them back into the URLs of my redirect actions.

> the problem is that i have 4 dynamic combo boxes and i always need to
> iterate over the request parameters with a Regexp to get and reset all
> the parameters of the combo boxes. the contents of the 4 combo boxes
> depend on the previously made selection.

I rarely do this, but others have been talking about this lately. Look
for messages that discuss "indexed" properties, which I think is what
you need.

> difficult to explain, sorry, hope you understand.

These kinds of things typically /are/ difficult to explain. Check the
archives for the past couple of weeks to see if there's something there
of any help. If not, post a new question to the list and include as much
detail as possible (examples are usually the quickest way to do that).

Hope that helps,
- -chris

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

iD4DBQFFhqR99CaO5/Lv0PARAqn8AJUS+sV1sFTB6pBhje3q8tK22YmgAJ9SMYHN
pXeb+A6fyIJdan8ctWhzHA==
=2Vtg
-----END PGP SIGNATURE-----

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


Re: DynaValidatorForm - cannot find bean

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Philippe,

Pille wrote:
> how can i access the getters and setters in of a DynaValidatorForm from
> within an action method?

You can use them as before.

> when i had a own form class i could do the following in a action method:
> 
> productForm = (MyOwnForm)form;
> 
> productForm.setComboArrayList(comboArrayListWithBeans);
> 
> with a dynamic form i cannot cast anymore or do i have to cast to a
> DynaValidatorForm? is it actually possible to do a cast or do i have to
> implement a ValidatorForm instead of using a DynaValidatorForm?

Oh. Check the javadoc for the DynaValidatorForm to see what methods are
available. You can certainly do what you are trying to do... you just
need to work with the API of the class you are using. I think you're
looking for something like this:

public void set(String name, Object value);

- -chris

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

iD8DBQFFhqTk9CaO5/Lv0PARAlgKAJ97YrSRcbrQfJJVCetg5LIOD6GlnQCgmLBn
d0j/iIQdIXsGHXrOTLiYuC8=
=BowI
-----END PGP SIGNATURE-----

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


Re: DynaValidatorForm - cannot find bean

Posted by Pille <al...@flipsonline.de>.

mano dasanayake wrote:
> Hi,
> Use PropertyUtils.setSimpleProperty(yourForm,"proptyName",object);
> 
> And 
> 
> PropertyUtils.getsimplePropert(yourform,"proprtyname") --> cast it to the
> required type..

ok, but i have a prepare action for the DynaValidatorForm where i
initialize one bean, put it to the ArrayList and then set the array list
as property of the form. but i´m not allowd to instantiate or cast the
form because of this:

<action path="/prepareBuyOnline"
                type="software.BuyOnlineAction"
                parameter="prepareForm">
            <forward name="success" path="/BuyOnline.jsp"/>

it seems that a form of type DynaValidatorFrom does´t allow the
attribute name="formName" in the prepare statement and that´s why i´m
unable to set the form property. i always get a ForwardConfig exception
when i try to do this but i need to set this form property in the
prepare statement. is there any other way to do this in a DynaValidatorForm?

> 
> Have a look
> http://www.ingrid.org/jajakarta/struts/struts1.0/en/target/documentation/api
> /org/apache/struts/util/PropertyUtils.html#getSimpleProperty(java.lang.Objec
> t,%20java.lang.String)
> 
> 
> Regards,
> Mano

thank you

regards
philippe

> 
> -----Original Message-----
> From: Pille [mailto:alsa-users@flipsonline.de] 
> Sent: Monday, December 18, 2006 5:48 AM
> To: Struts Users Mailing List
> Subject: Re: DynaValidatorForm - cannot find bean
> 
> how can i access the getters and setters in of a DynaValidatorForm from
> within an action method?
> 
> when i had a own form class i could do the following in a action method:
> 
> productForm = (MyOwnForm)form;
> 
> productForm.setComboArrayList(comboArrayListWithBeans);
> 
> with a dynamic form i cannot cast anymore or do i have to cast to a
> DynaValidatorForm? is it actually possible to do a cast or do i have to
> implement a ValidatorForm instead of using a DynaValidatorForm?
> thank you
> 
> 
> Pille wrote:
>> Christopher Schultz wrote:
>>> 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
>> ok. i understand.
>>
>> how can i set a property of the form, that is used and needed in the jsp
>> of the form after editing?
>> how can i set a property of a dyna form from within an action? how do i
>> make sure that this property will be still set after submission and
>> redirecting over 2 sites?
>>
>> the problem is that i have 4 dynamic combo boxes and i always need to
>> iterate over the request parameters with a Regexp to get and reset all
>> the parameters of the combo boxes. the contents of the 4 combo boxes
>> depend on the previously made selection.
>> one row of the combo boxes is hold in an ArrayList which is a property
>> of the DynaValidatorForm. the ArrayList itself holds the Beans. after
>> making a selection in the last combo box, i call the action and add a
>> new element in the array list. in the jsp i iterate over this ArrayList
>> and a second line with no selection is displayed. for each combo box i
>> submit the form with the javascript onchange event to generate new
>> values (or maybe a new row with combo boxes).
>> i have one row of 4 combo boxes. after a selection in the last combo box
>> of the last row i create a new arraylist item and a new line with new
>> combo boxes is displayed.
>> the selection possibilities are stored in the bean (ArrayList with
>> Beans) too because some selection possibilities are different from
>> others e.g. in the third combo box in the first row there are different
>> selection values than in the third combo box in second row because of
>> different selections in second combo in first and second row. difficult
>> to explain, sorry, hope you understand.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

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


RE: DynaValidatorForm - cannot find bean

Posted by mano dasanayake <ma...@mubasher.net>.
Hi,
Use PropertyUtils.setSimpleProperty(yourForm,"proptyName",object);

And 

PropertyUtils.getsimplePropert(yourform,"proprtyname") --> cast it to the
required type..

Have a look
http://www.ingrid.org/jajakarta/struts/struts1.0/en/target/documentation/api
/org/apache/struts/util/PropertyUtils.html#getSimpleProperty(java.lang.Objec
t,%20java.lang.String)


Regards,
Mano

-----Original Message-----
From: Pille [mailto:alsa-users@flipsonline.de] 
Sent: Monday, December 18, 2006 5:48 AM
To: Struts Users Mailing List
Subject: Re: DynaValidatorForm - cannot find bean

how can i access the getters and setters in of a DynaValidatorForm from
within an action method?

when i had a own form class i could do the following in a action method:

productForm = (MyOwnForm)form;

productForm.setComboArrayList(comboArrayListWithBeans);

with a dynamic form i cannot cast anymore or do i have to cast to a
DynaValidatorForm? is it actually possible to do a cast or do i have to
implement a ValidatorForm instead of using a DynaValidatorForm?
thank you


Pille wrote:
> 
> Christopher Schultz wrote:
>> 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
> 
> ok. i understand.
> 
> how can i set a property of the form, that is used and needed in the jsp
> of the form after editing?
> how can i set a property of a dyna form from within an action? how do i
> make sure that this property will be still set after submission and
> redirecting over 2 sites?
> 
> the problem is that i have 4 dynamic combo boxes and i always need to
> iterate over the request parameters with a Regexp to get and reset all
> the parameters of the combo boxes. the contents of the 4 combo boxes
> depend on the previously made selection.
> one row of the combo boxes is hold in an ArrayList which is a property
> of the DynaValidatorForm. the ArrayList itself holds the Beans. after
> making a selection in the last combo box, i call the action and add a
> new element in the array list. in the jsp i iterate over this ArrayList
> and a second line with no selection is displayed. for each combo box i
> submit the form with the javascript onchange event to generate new
> values (or maybe a new row with combo boxes).
> i have one row of 4 combo boxes. after a selection in the last combo box
> of the last row i create a new arraylist item and a new line with new
> combo boxes is displayed.
> the selection possibilities are stored in the bean (ArrayList with
> Beans) too because some selection possibilities are different from
> others e.g. in the third combo box in the first row there are different
> selection values than in the third combo box in second row because of
> different selections in second combo in first and second row. difficult
> to explain, sorry, hope you understand.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

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





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


Re: DynaValidatorForm - cannot find bean

Posted by Pille <al...@flipsonline.de>.
how can i access the getters and setters in of a DynaValidatorForm from
within an action method?

when i had a own form class i could do the following in a action method:

productForm = (MyOwnForm)form;

productForm.setComboArrayList(comboArrayListWithBeans);

with a dynamic form i cannot cast anymore or do i have to cast to a
DynaValidatorForm? is it actually possible to do a cast or do i have to
implement a ValidatorForm instead of using a DynaValidatorForm?
thank you


Pille wrote:
> 
> Christopher Schultz wrote:
>> 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
> 
> ok. i understand.
> 
> how can i set a property of the form, that is used and needed in the jsp
> of the form after editing?
> how can i set a property of a dyna form from within an action? how do i
> make sure that this property will be still set after submission and
> redirecting over 2 sites?
> 
> the problem is that i have 4 dynamic combo boxes and i always need to
> iterate over the request parameters with a Regexp to get and reset all
> the parameters of the combo boxes. the contents of the 4 combo boxes
> depend on the previously made selection.
> one row of the combo boxes is hold in an ArrayList which is a property
> of the DynaValidatorForm. the ArrayList itself holds the Beans. after
> making a selection in the last combo box, i call the action and add a
> new element in the array list. in the jsp i iterate over this ArrayList
> and a second line with no selection is displayed. for each combo box i
> submit the form with the javascript onchange event to generate new
> values (or maybe a new row with combo boxes).
> i have one row of 4 combo boxes. after a selection in the last combo box
> of the last row i create a new arraylist item and a new line with new
> combo boxes is displayed.
> the selection possibilities are stored in the bean (ArrayList with
> Beans) too because some selection possibilities are different from
> others e.g. in the third combo box in the first row there are different
> selection values than in the third combo box in second row because of
> different selections in second combo in first and second row. difficult
> to explain, sorry, hope you understand.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 

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


Re: DynaValidatorForm - cannot find bean

Posted by Pille <al...@flipsonline.de>.

Christopher Schultz wrote:
> 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

ok. i understand.

how can i set a property of the form, that is used and needed in the jsp
of the form after editing?
how can i set a property of a dyna form from within an action? how do i
make sure that this property will be still set after submission and
redirecting over 2 sites?

the problem is that i have 4 dynamic combo boxes and i always need to
iterate over the request parameters with a Regexp to get and reset all
the parameters of the combo boxes. the contents of the 4 combo boxes
depend on the previously made selection.
one row of the combo boxes is hold in an ArrayList which is a property
of the DynaValidatorForm. the ArrayList itself holds the Beans. after
making a selection in the last combo box, i call the action and add a
new element in the array list. in the jsp i iterate over this ArrayList
and a second line with no selection is displayed. for each combo box i
submit the form with the javascript onchange event to generate new
values (or maybe a new row with combo boxes).
i have one row of 4 combo boxes. after a selection in the last combo box
of the last row i create a new arraylist item and a new line with new
combo boxes is displayed.
the selection possibilities are stored in the bean (ArrayList with
Beans) too because some selection possibilities are different from
others e.g. in the third combo box in the first row there are different
selection values than in the third combo box in second row because of
different selections in second combo in first and second row. difficult
to explain, sorry, hope you understand.

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



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


Re: DynaValidatorForm - cannot find bean

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----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