You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Bjørn T Johansen <bt...@havleik.no> on 2003/09/27 18:55:18 UTC

Access to the form bean from jsp?

I need to access the form from my jsp page, but I can't seem to find a
way to do this.. I need a name of the form to access but what is the
name of the form instance that Struts generate? If I have a form named
LoginForm does Struts make an instance called loginForm or does it
choose a random name or?


Regards,

BTJ


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


Re: Access to the form bean from jsp?

Posted by Bjørn T Johansen <bt...@havleik.no>.
Yes, you are absolutely correct; it uses the name I defined in
struts-config, I should have known...

Thanks.... :)


BTJ

On Sat, 2003-09-27 at 19:11, Anders Hermansen wrote:
> * Bjørn T Johansen (btj@havleik.no) wrote:
> > I need to access the form from my jsp page, but I can't seem to find a
> > way to do this.. I need a name of the form to access but what is the
> > name of the form instance that Struts generate? If I have a form named
> > LoginForm does Struts make an instance called loginForm or does it
> > choose a random name or?
> 
> You specify the name when you declare a form bean in struts-config.xml
> 
> in example:
>   <form-bean name="LoginForm" type="com.company.forms.LoginForm" />
> 
> In the jsp you can define a variable to point to this form using:
>   <bean:define id="myLoginForm" name="LoginForm" type="com.company.forms.LoginForm" />
> you can then use myLoginForm in any scriptlet.
> 
> You can also easily extract specific properties:
>   <bean:define id="theUsername" name="LoginForm" property="username"/>
> 
> or you can print them directly:
>   <bean:write name="LoginForm" property="username"/>
> 
> This is all from memory, so I hope it's correct.
> 
> 
> Hope this helps,
> Anders
> 
> --
> Anders Hermansen
> YoYo Mobile as
> 
> ---------------------------------------------------------------------
> 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: Access to the form bean from jsp?

Posted by Anders Hermansen <an...@yoyo.no>.
* Bjørn T Johansen (btj@havleik.no) wrote:
> I need to access the form from my jsp page, but I can't seem to find a
> way to do this.. I need a name of the form to access but what is the
> name of the form instance that Struts generate? If I have a form named
> LoginForm does Struts make an instance called loginForm or does it
> choose a random name or?

You specify the name when you declare a form bean in struts-config.xml

in example:
  <form-bean name="LoginForm" type="com.company.forms.LoginForm" />

In the jsp you can define a variable to point to this form using:
  <bean:define id="myLoginForm" name="LoginForm" type="com.company.forms.LoginForm" />
you can then use myLoginForm in any scriptlet.

You can also easily extract specific properties:
  <bean:define id="theUsername" name="LoginForm" property="username"/>

or you can print them directly:
  <bean:write name="LoginForm" property="username"/>

This is all from memory, so I hope it's correct.


Hope this helps,
Anders

--
Anders Hermansen
YoYo Mobile as

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