You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Susan Bradeen <Su...@softlanding.com> on 2003/05/01 21:37:24 UTC

formbeans self-populating

There is something about ActionForms that I just don't get yet. I hope 
someone can help or at least just confirm.

ActionA -> someA.jsp -> click link on jsp -> ActionB -> someB.jsp

ActionA uses formA and ActionB uses formB, but both forms contain a 
property "itemID".

ActionA.execute() has:
    MyFormA formA = (MyFormA) form
    formA.setItemID(StringFromSomewhere);
    ...
    forward to success --> someA.jsp.

someA.jsp has the link:
<html:link page="/actionB.do" paramId="itemID" paramName="formA" paramProperty="itemID">Click</html:link>

ActionB.execute() has:
    MyFormB formB = (MyFormB) form
    System.out.println("item ID = " + formB.getItemID());
    ...

When I run through this ... without setting any formB properties in 
ActionB, the console displays itemID as the value passed by the link, set 
from formA. I keep expecting this value to be blank since I didn't 
actually set it (i.e. formB.setItemID(request.getParameter("itemID"));), 
but it is already populated. 

So "form", within the Action classes, kind of just sits out there, and 
takes on whatever class you cast it to be, and automatically sets  any 
property values coming through that it contains? 

Thanks,
Susan Bradeen

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


RE: formbeans self-populating

Posted by Robert Taylor <rt...@mulework.com>.
> regardless of
> which form you are working with.

Correction:

Struts populates the form which is associated to the
action invoked for a specified action mapping.

But it is still true that Struts does populate
the form using request parameters and reflection.
That is why itemID exists in the form declared for
ActionB although you didn't explicitely set the value.
Struts "sees" an itemID in the request and uses reflection
to set that value in MyFormB.

robert


> -----Original Message-----
> From: Robert Taylor [mailto:rtaylor@mulework.com]
> Sent: Thursday, May 01, 2003 4:05 PM
> To: Struts Users Mailing List
> Subject: RE: formbeans self-populating
>
>
> Susan, Struts populates form attributes when those attribute names
> correspond to
> parameter names in the request. That is assuming the form
> attribute mutators are public. So yes, if two forms are different but have
> overlapping attributes then those attributes will get populate by
> Struts if
> their corresponding names exist in the request as parameters;
>
> robert
>
> > -----Original Message-----
> > From: Susan Bradeen [mailto:SusanB@softlanding.com]
> > Sent: Thursday, May 01, 2003 3:37 PM
> > To: struts-user@jakarta.apache.org
> > Subject: formbeans self-populating
> >
> >
> > There is something about ActionForms that I just don't get yet. I hope
> > someone can help or at least just confirm.
> >
> > ActionA -> someA.jsp -> click link on jsp -> ActionB -> someB.jsp
> >
> > ActionA uses formA and ActionB uses formB, but both forms contain a
> > property "itemID".
> >
> > ActionA.execute() has:
> >     MyFormA formA = (MyFormA) form
> >     formA.setItemID(StringFromSomewhere);
> >     ...
> >     forward to success --> someA.jsp.
> >
> > someA.jsp has the link:
> > <html:link page="/actionB.do" paramId="itemID" paramName="formA"
> > paramProperty="itemID">Click</html:link>
> >
> > ActionB.execute() has:
> >     MyFormB formB = (MyFormB) form
> >     System.out.println("item ID = " + formB.getItemID());
> >     ...
> >
> > When I run through this ... without setting any formB properties in
> > ActionB, the console displays itemID as the value passed by the
> link, set
> > from formA. I keep expecting this value to be blank since I didn't
> > actually set it (i.e. formB.setItemID(request.getParameter("itemID"));),
> > but it is already populated.
> >
> > So "form", within the Action classes, kind of just sits out there, and
> > takes on whatever class you cast it to be, and automatically sets  any
> > property values coming through that it contains?
> >
> > Thanks,
> > Susan Bradeen
> >
> > ---------------------------------------------------------------------
> > 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
>


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


RE: formbeans self-populating

Posted by Robert Taylor <rt...@mulework.com>.
Susan, Struts populates form attributes when those attribute names
correspond to
parameter names in the request. That is assuming the form
attribute mutators are public. So yes, if two forms are different but have
overlapping attributes then those attributes will get populate by Struts if
their corresponding names exist in the request as parameters; regardless of
which form you are working with.

robert

> -----Original Message-----
> From: Susan Bradeen [mailto:SusanB@softlanding.com]
> Sent: Thursday, May 01, 2003 3:37 PM
> To: struts-user@jakarta.apache.org
> Subject: formbeans self-populating
>
>
> There is something about ActionForms that I just don't get yet. I hope
> someone can help or at least just confirm.
>
> ActionA -> someA.jsp -> click link on jsp -> ActionB -> someB.jsp
>
> ActionA uses formA and ActionB uses formB, but both forms contain a
> property "itemID".
>
> ActionA.execute() has:
>     MyFormA formA = (MyFormA) form
>     formA.setItemID(StringFromSomewhere);
>     ...
>     forward to success --> someA.jsp.
>
> someA.jsp has the link:
> <html:link page="/actionB.do" paramId="itemID" paramName="formA"
> paramProperty="itemID">Click</html:link>
>
> ActionB.execute() has:
>     MyFormB formB = (MyFormB) form
>     System.out.println("item ID = " + formB.getItemID());
>     ...
>
> When I run through this ... without setting any formB properties in
> ActionB, the console displays itemID as the value passed by the link, set
> from formA. I keep expecting this value to be blank since I didn't
> actually set it (i.e. formB.setItemID(request.getParameter("itemID"));),
> but it is already populated.
>
> So "form", within the Action classes, kind of just sits out there, and
> takes on whatever class you cast it to be, and automatically sets  any
> property values coming through that it contains?
>
> Thanks,
> Susan Bradeen
>
> ---------------------------------------------------------------------
> 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


RE: formbeans self-populating

Posted by Ravi Kora <rk...@1bigthink.com>.
It sets the values to the form which you have configured the action for.
You must have had something like this in your struts-config.xml.

<action path="ActionB" type="ActionB" name="MyFormB" scope="request">
  <forward name="success" path="xxx"/>
</action>

So, whenever you submit form to ActionB, the form(eventually typecasted
as MyFormB) will be automatically filled with the values on the html
page.

HTH,
Ravi


> -----Original Message-----
> From: Susan Bradeen [mailto:SusanB@softlanding.com] 
> Sent: Thursday, May 01, 2003 3:37 PM
> To: struts-user@jakarta.apache.org
> Subject: formbeans self-populating
> 
> 
> There is something about ActionForms that I just don't get 
> yet. I hope 
> someone can help or at least just confirm.
> 
> ActionA -> someA.jsp -> click link on jsp -> ActionB -> someB.jsp
> 
> ActionA uses formA and ActionB uses formB, but both forms contain a 
> property "itemID".
> 
> ActionA.execute() has:
>     MyFormA formA = (MyFormA) form
>     formA.setItemID(StringFromSomewhere);
>     ...
>     forward to success --> someA.jsp.
> 
> someA.jsp has the link:
> <html:link page="/actionB.do" paramId="itemID" 
> paramName="formA" paramProperty="itemID">Click</html:link>
> 
> ActionB.execute() has:
>     MyFormB formB = (MyFormB) form
>     System.out.println("item ID = " + formB.getItemID());
>     ...
> 
> When I run through this ... without setting any formB properties in 
> ActionB, the console displays itemID as the value passed by 
> the link, set 
> from formA. I keep expecting this value to be blank since I didn't 
> actually set it (i.e. 
> formB.setItemID(request.getParameter("itemID"));), 
> but it is already populated. 
> 
> So "form", within the Action classes, kind of just sits out 
> there, and 
> takes on whatever class you cast it to be, and automatically 
> sets  any 
> property values coming through that it contains? 
> 
> Thanks,
> Susan Bradeen
> 
> ---------------------------------------------------------------------
> 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