> for using reusable actions it would be great if there is a possibility
> to give parameters to a specific action. (if possible in the
> action.xml/struts-config.xml).
> one example is a reusable signup action where one parameter defines
> which form fields (name, e-mail) are necessary/ mandatory.
> it should be possible to use one action more times with differently
> configured parameters in one webapp.

hmm... As far as determining required form fields, this should really be a
job for a form-bean object.

Perhaps you might be thinking of something a little more dynamic where
perhaps you have a fairly generic action which you would like to reuse
without tying it to any particular form? and specify different form
parameters that are required in the action mapping definition?  If this is
so, you can take two approaches to doing this (that I know of, based on the
existing code).  In either case, you will have to implement your own
ActionMapping class.  With the properties you wish to set via the xml config
file.

Please keep in mind that I haven't specifically done such a thing, but I do
have the general idea on how it would work. (i.e. if I'm wrong, don't yell
at me ;) ).

If you want to specify custom properties for an action mapping on a case by
case (i.e. per action mapping) basis, you can utilize the provided
setProperty rule that is added to the digester in the ActionServlet for the
action tag.

from ActionServlet:
-----------------------
(...)
 digester.addSetProperty
    ("struts-config/action-mappings/action/set-property",
     "property", "value");
(...)


You could then insert the corresponding <set-property> tags for any
particular action you wish to use your mapping for.  This is also avaiable
for the other Struts related objects, like form-bean, forward, etc.  You
would, of course, need to override the default class that is instantiated
for "struts-config/action-mapping/action".  You do this by using the
"className" attribute of the action tag.

something like... (THIS MAY BE WRONG, but close)

   <action     path="/logon"
               type="org.apache.struts.example.LogonAction"
              scope="request"
          className="com.your.action.MappingClass">
        <set-property>
            <property>reqField</property>
            <value>username</value>
        </set-property>
        <forward .../>
   </action>

maybe?...  <set-property property="reqField" value="username"/>

Anybody know the difinitive layout for this?



The alternative would be to have the ActionServlet use your actionmapping
class for all actionmappings by specifying the servlet init parameter
"mapping" in the web.xml file.  In which case you can just put the
corresponding property tag in the action tag.
   <action     path="/logon"
               type="org.apache.struts.example.LogonAction"
              scope="request"
             reqField="username">
        <forward .../>
   </action>


You could then have access to the parameters in your action.


Hope this helps ;)

Scott

> -----Original Message-----
> From: christian reichlin [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 30, 2001 11:24 AM
> To: [EMAIL PROTECTED]
> Subject: parameters for actions
>
>
> hi,
>
> im looking for an easy way to "configure" actions.
>
> for using reusable actions it would be great if there is a possibility
> to give parameters to a specific action. (if possible in the
> action.xml/struts-config.xml).
> one example is a reusable signup action where one parameter defines
> which form fields (name, e-mail) are necessary/ mandatory.
> it should be possible to use one action more times with differently
> configured parameters in one webapp.
>
> i didn't found something like this one the stuts pages, can someone tell
> me if something similar like this already exist or if something like
> this will be added in future or if this is something stupid and
> shouldn't be solved this way.
>
> cheers,
> christian
>
>

Reply via email to