You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Kunal H. Parikh" <ku...@carsales.com.au> on 2004/04/20 06:21:00 UTC

Must the from name and action name MATCH ?

Hi All!

I was wondering if I could attach a form with a name different to	that
of the action.

i.e. 
===========
<form name="searchForm"
	type="custom.searchForm"
/>

<action name="searchAction"
...
...
/>
===========

I want to follow this pattern of naming conventions:
ActionName: searchAction
FromName: searchForm
ForwardName: searchResults (Assuming that I only have one forward for every
action)

TIA,

Kunal



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


Re: Must the from name and action name MATCH ?

Posted by Bill Siggelkow <bi...@bellsouth.net>.
Kunal,

The "name" attribute specified for an <action> corresponds to the "name" 
attribute of the <form-bean>.  This is how you relate a form to an 
action.  If the names don't match then the Action won't know which form 
to use.

As far as conventions, I prefer the form names and the action paths to 
start with an uppercase character -- its then easier to distinguish them 
from form properties.

So you have the following:

<form-bean name="MyForm" type="com.foo.MyForm"/>
...
<action path="/DoSomething"
         name="/MyForm"
         type="com.foo.DoSomethingAction"/>

In addition, you will find that you have two actions for a JSP page -- 
one that sets up the data and forwards to the page for rendering.  And 
the second that is responsible for processing the page on form 
submission.  It is good to follow a convention for this pattern.  For 
example, you can use "ViewBlah" for the page that sets up the page, and 
"ProcessBlah" for the page to which the form is submitted.  Something like:

<action path="/ViewWidget"
         name="/WidgetForm"
         type="com.foo.ViewWidgetAction">
   <forward name="success" path="view_widget.jsp"/>
</action>

<action path="/ProcessWidget"
         name="/WidgetForm"
         type="com.foo.ProcessWidgetAction"
     validate="true"
        input="view_widget.jsp"/>


Kunal H. Parikh wrote:
> I was wondering if I could attach a form with a name different to	that
> of the action.
> 
> i.e. 
> ===========
> <form name="searchForm"
> 	type="custom.searchForm"
> />
> 
> <action name="searchAction"
> ...
> ...
> />
> ===========
> 
> I want to follow this pattern of naming conventions:
> ActionName: searchAction
> FromName: searchForm
> ForwardName: searchResults (Assuming that I only have one forward for every
> action)
> 
> TIA,
> 
> Kunal


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