You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Puneet Lakhina <pu...@gmail.com> on 2006/10/11 14:59:33 UTC

html form instantiating form bean

Hi,
This has to be one of the most bewildering thing I have faced in my 3 months
of learning struts.
Now I have an action(PreapreAction) which I use to prepare a page for
display. This for fetches values from a Database and creates an instance of
the formbean and puts values into the form bean. Now i do
request.setAttribute("formBeanName",formBeanObject). And then forwards to
the page which has something like this
<html:form action="/fooAction">

......
</html:form>

the fooAction has formBeanName as its form bean defined in the struts
config. But Im not able to get any values into the fields in my form.

However if I do this
<bean:write name="formBeanName" property="someProperty" />. It prints the
correct value i.e. the value that I set in the PrepareAction. Does this mean
that there are two form bean in the request scope. but theere cant be two
attributes with the same name.

So i printed all the attribute names and their class in my jsp page.
Turns out there is another attribute of type formBeanObject in my request
under the key org.apache.struts.taglib.html.BEAN

Why is this happening?? I even tried using they key
org.apache.struts.taglib.html.BEAN in my PrepareAction but still ti does not
work.

SO i printed a message from the default constructor of my form bean. Thats
printed twice, once when i instantiate it in PrepareAction and again when
the page is loaded.

Plz plz help me sort this out.

-- 
Puneet

Re: html form instantiating form bean

Posted by Puneet Lakhina <pu...@gmail.com>.
On 10/11/06, Ed Griebel <ed...@gmail.com> wrote:
>
> You should not instantiate manually your own formbean nor put it into
> the request scope, you must use the formbean passed into your action
> class via the ActionForm object.


Ok I think my question isnt clear.

I have two action classes PrepareAction and SubmitAction.
I have one page submitInputPage.jsp

The formBeanName is associated with SubmitAction. So what the PrepareAction
is looking to do is create a formBeanObject and put it in request scope and
forward to the submitInputPage.jsp.

So basically PrepareAction has a different form bean associated with it than
formBeanName. formBeanName is associated with SubmitAction and not
PrepareAction. Hence typecasting wont work.

When you get the handle to the formbean you can either cast the
> formbean to it's real class or you can use
> BeanUtils.populate(formbean, "param_1", value1) to get your values
> into the formbean. Hopefully I have not missed the point of your
> question.
>
> HTH,
> -ed
>
> On 10/11/06, Puneet Lakhina <pu...@gmail.com> wrote:
> > Hi,
> > This has to be one of the most bewildering thing I have faced in my 3
> months
> > of learning struts.
> > Now I have an action(PreapreAction) which I use to prepare a page for
> > display. This for fetches values from a Database and creates an instance
> of
> > the formbean and puts values into the form bean. Now i do
> > request.setAttribute("formBeanName",formBeanObject). And then forwards
> to
> > the page which has something like this
> > <html:form action="/fooAction">
> >
> > ......
> > </html:form>
> >
> > the fooAction has formBeanName as its form bean defined in the struts
> > config. But Im not able to get any values into the fields in my form.
> >
> > However if I do this
> > <bean:write name="formBeanName" property="someProperty" />. It prints
> the
> > correct value i.e. the value that I set in the PrepareAction. Does this
> mean
> > that there are two form bean in the request scope. but theere cant be
> two
> > attributes with the same name.
> >
> > So i printed all the attribute names and their class in my jsp page.
> > Turns out there is another attribute of type formBeanObject in my
> request
> > under the key org.apache.struts.taglib.html.BEAN
> >
> > Why is this happening?? I even tried using they key
> > org.apache.struts.taglib.html.BEAN in my PrepareAction but still ti does
> not
> > work.
> >
> > SO i printed a message from the default constructor of my form bean.
> Thats
> > printed twice, once when i instantiate it in PrepareAction and again
> when
> > the page is loaded.
> >
> > Plz plz help me sort this out.
> >
> > --
> > Puneet
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Puneet

Re: html form instantiating form bean

Posted by Ed Griebel <ed...@gmail.com>.
You should not instantiate manually your own formbean nor put it into
the request scope, you must use the formbean passed into your action
class via the ActionForm object.

When you get the handle to the formbean you can either cast the
formbean to it's real class or you can use
BeanUtils.populate(formbean, "param_1", value1) to get your values
into the formbean. Hopefully I have not missed the point of your
question.

HTH,
-ed

On 10/11/06, Puneet Lakhina <pu...@gmail.com> wrote:
> Hi,
> This has to be one of the most bewildering thing I have faced in my 3 months
> of learning struts.
> Now I have an action(PreapreAction) which I use to prepare a page for
> display. This for fetches values from a Database and creates an instance of
> the formbean and puts values into the form bean. Now i do
> request.setAttribute("formBeanName",formBeanObject). And then forwards to
> the page which has something like this
> <html:form action="/fooAction">
>
> ......
> </html:form>
>
> the fooAction has formBeanName as its form bean defined in the struts
> config. But Im not able to get any values into the fields in my form.
>
> However if I do this
> <bean:write name="formBeanName" property="someProperty" />. It prints the
> correct value i.e. the value that I set in the PrepareAction. Does this mean
> that there are two form bean in the request scope. but theere cant be two
> attributes with the same name.
>
> So i printed all the attribute names and their class in my jsp page.
> Turns out there is another attribute of type formBeanObject in my request
> under the key org.apache.struts.taglib.html.BEAN
>
> Why is this happening?? I even tried using they key
> org.apache.struts.taglib.html.BEAN in my PrepareAction but still ti does not
> work.
>
> SO i printed a message from the default constructor of my form bean. Thats
> printed twice, once when i instantiate it in PrepareAction and again when
> the page is loaded.
>
> Plz plz help me sort this out.
>
> --
> Puneet
>
>

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