You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Cardon <mi...@bendcable.com> on 2003/11/06 16:35:04 UTC

Best Practices in Struts for Form objects?

Hello,

If I have 5 Action classes that all need to reference the same Form object,
should I map each Action to the same form name, or use different names for
each of the Forms in the Actions?  Does it make a difference if I’m using
session scope vs. request scope?

Example using the same form names, same form class:

<form-bean name="pwForm" type="mim.struts.form.SelectForm"/>

    <action    path="/teacherPw"
               type="mim.struts.action.pw.StudentPwAction"
               name="pwForm"
              scope="request"
           validate="false"
          parameter="dispatch">
      <forward name="success"	path="mim.pw.list"/>
    </action>

    <action    path="/studentPw"
               type="mim.struts.action.pw.StudentPwAction"
               name="pwForm"
              scope="request"
           validate="false"
          parameter="dispatch">
      <forward name="success"	path="mim.pw.list"/>
    </action>

... 3 more actions ....


Example using diferent form names, same form class:

<form-bean name="teacherpwForm" type="mim.struts.form.SelectForm"/>
<form-bean name="studentpwForm" type="mim.struts.form.SelectForm"/>

    <action    path="/teacherPw"
               type="mim.struts.action.pw.StudentPwAction"
               name="teacherpwForm"
              scope="request"
           validate="false"
          parameter="dispatch">
      <forward name="success"	path="mim.pw.list"/>
    </action>

    <action    path="/studentPw"
               type="mim.struts.action.pw.StudentPwAction"
               name="studentpwForm"
              scope="request"
           validate="false"
          parameter="dispatch">
      <forward name="success"	path="mim.pw.list"/>
    </action>

... 3 more actions ....

Thanks


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


Re: Best Practices in Struts for Form objects?

Posted by Frers Michael <fr...@Sisis.de>.
Hello
it totally depends what you need.

different names:
if u use different names than there will be created five different forms,
each under an other name.
if all are in request it makes not really sense to do this because they are
deleted if the request is over.

but if you use them in session then it could make sense
then you could have up to five formbeans in scope and get to their values
every time, but you have to know which form you actually need
if they are stored under the same name then only once is created the
formbean so values will be availble for every action which uses it
(except you explicite destroy it)

Michael

----- Original Message -----
From: "Michael Cardon" <mi...@bendcable.com>
To: <st...@jakarta.apache.org>
Sent: Thursday, November 06, 2003 4:35 PM
Subject: Best Practices in Struts for Form objects?


> Hello,
>
> If I have 5 Action classes that all need to reference the same Form
object,
> should I map each Action to the same form name, or use different names for
> each of the Forms in the Actions?  Does it make a difference if I'm using
> session scope vs. request scope?
>
> Example using the same form names, same form class:
>
> <form-bean name="pwForm" type="mim.struts.form.SelectForm"/>
>
>     <action    path="/teacherPw"
>                type="mim.struts.action.pw.StudentPwAction"
>                name="pwForm"
>               scope="request"
>            validate="false"
>           parameter="dispatch">
>       <forward name="success" path="mim.pw.list"/>
>     </action>
>
>     <action    path="/studentPw"
>                type="mim.struts.action.pw.StudentPwAction"
>                name="pwForm"
>               scope="request"
>            validate="false"
>           parameter="dispatch">
>       <forward name="success" path="mim.pw.list"/>
>     </action>
>
> ... 3 more actions ....
>
>
> Example using diferent form names, same form class:
>
> <form-bean name="teacherpwForm" type="mim.struts.form.SelectForm"/>
> <form-bean name="studentpwForm" type="mim.struts.form.SelectForm"/>
>
>     <action    path="/teacherPw"
>                type="mim.struts.action.pw.StudentPwAction"
>                name="teacherpwForm"
>               scope="request"
>            validate="false"
>           parameter="dispatch">
>       <forward name="success" path="mim.pw.list"/>
>     </action>
>
>     <action    path="/studentPw"
>                type="mim.struts.action.pw.StudentPwAction"
>                name="studentpwForm"
>               scope="request"
>            validate="false"
>           parameter="dispatch">
>       <forward name="success" path="mim.pw.list"/>
>     </action>
>
> ... 3 more actions ....
>
> Thanks
>
>
> ---------------------------------------------------------------------
> 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: Best Practices in Struts for Form objects?

Posted by Philip Mark Donaghy <go...@yahoo.com>.
If all of your Forms have exactly the same properties
then use the same form mapping for all your actions.

If all of your Forms share some properties then use
different forms for each action. Each of these forms
would extend a generic form which extends of course
ActionForm or ValidatorForm.

Phil

--- Michael Cardon <mi...@bendcable.com> wrote:
> Hello,
> 
> If I have 5 Action classes that all need to
> reference the same Form object,
> should I map each Action to the same form name, or
> use different names for
> each of the Forms in the Actions?  Does it make a
> difference if I�m using
> session scope vs. request scope?
> 
> Example using the same form names, same form class:
> 
> <form-bean name="pwForm"
> type="mim.struts.form.SelectForm"/>
> 
>     <action    path="/teacherPw"
>               
> type="mim.struts.action.pw.StudentPwAction"
>                name="pwForm"
>               scope="request"
>            validate="false"
>           parameter="dispatch">
>       <forward name="success"	path="mim.pw.list"/>
>     </action>
> 
>     <action    path="/studentPw"
>               
> type="mim.struts.action.pw.StudentPwAction"
>                name="pwForm"
>               scope="request"
>            validate="false"
>           parameter="dispatch">
>       <forward name="success"	path="mim.pw.list"/>
>     </action>
> 
> ... 3 more actions ....
> 
> 
> Example using diferent form names, same form class:
> 
> <form-bean name="teacherpwForm"
> type="mim.struts.form.SelectForm"/>
> <form-bean name="studentpwForm"
> type="mim.struts.form.SelectForm"/>
> 
>     <action    path="/teacherPw"
>               
> type="mim.struts.action.pw.StudentPwAction"
>                name="teacherpwForm"
>               scope="request"
>            validate="false"
>           parameter="dispatch">
>       <forward name="success"	path="mim.pw.list"/>
>     </action>
> 
>     <action    path="/studentPw"
>               
> type="mim.struts.action.pw.StudentPwAction"
>                name="studentpwForm"
>               scope="request"
>            validate="false"
>           parameter="dispatch">
>       <forward name="success"	path="mim.pw.list"/>
>     </action>
> 
> ... 3 more actions ....
> 
> Thanks
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


=====
Java Web Application Architect
mapimage.com - Java and GIS
struts1.1:tomcat4.1.27:linuxRH8

__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

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