struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Chisholm" <David_Chish...@i2.com>
Subject RE: Struts--question about bean/form name.
Date Wed, 21 Jun 2000 13:27:55 GMT
In this case though I would like to avoid a custom mapping class that adds
set/get() accessors for new attributes because the attributes of the actions
may vary widely.

The Actions I'm using in my existing framework often need static
initialization parameters to customize their processing.  So what I do is
load all non-standard attributes into a HashMap stored in the Action's
ActionConfig instance (equivalent of ActionMapping).  The Action can then
add as many custom parameters as it wants to the action configuration file
and fetch them by name from it's ActionConfig HashMap at runtime.

My from I've read so far of the code, struts only uses one type of
ActionMapping and so it would have to have set/get() methods for all of the
custom attributes of all Actions.  This isn't practical if you have lots of
custom attributes that are unique to each Action.

Can you create a custom ActionMapping class that can store arbitrary
information?  (This doesn't appear possible.)  How about a new feature that
allows you to specify the custom ActionMapping on a per action basis in the
action.xml file.  For example:

 <action path="/logon"
   actionClass="org.apache.struts.example.LogonAction"
   formAttribute="logonForm"
   formClass="org.apache.struts.example.LogonForm"
   inputForm="/logon.jsp"
   actionMapping="my.custom.LogonActionMapping”
   useDefaultHomePage=”true”>
     <forward name="logon"      path="/logon.jsp"/>
     <forward name="success"    path="/mainMenu.jsp"/>
 </action>

When parsed, the custom action mapping would be instantiated and used to
store the custom ‘useDefaultHomePage’ attribute.

Is this feasible?

David


> -----Original Message-----
> From: jhut@inst.strykercorp.com [mailto:jhut@inst.strykercorp.com]
> Sent: Wednesday, June 21, 2000 7:48 AM
> To: struts-user@jakarta.apache.org
> Subject: RE: Struts--question about bean/form name.
>
>
> On Wed, 21 Jun 2000, David Chisholm wrote:
>
> > On a similar note, can you associate non-standard attributes
> for an action
> > in the action.xml, and then retrieve those values in the
> Action.perform()
> > method?  For example, adding the useDefaultHomePage attribute
> shown below to
> > the example logon action:
> >
> >   <action path="/logon"
> >     actionClass="org.apache.struts.example.LogonAction"
> >     formAttribute="logonForm"
> >     formClass="org.apache.struts.example.LogonForm"
> >     inputForm="/logon.jsp">
> >     <forward name="logon"      path="/logon.jsp"/>
> >     <forward name="success"    path="/mainMenu.jsp"/>
> >     useDefaultHomePage="true"
> >   </action>
>
> You can provide a custom ApplicationMapping that contains properties
> corresponding to additional attributes to the action tag.  For example
> with your example (putting the attribute in the tag):
>
> <action path="/logon"
>   actionClass="org.apache.struts.example.LogonAction"
>   formAttribute="logonForm"
>   formClass="org.apache.struts.example.LogonForm"
>   inputForm="/logon.jsp"
>   useDefaultHomePage="true">
>     <forward name="logon"      path="/logon.jsp"/>
>     <forward name="success"    path="/mainMenu.jsp"/>
> </action>
>
> You can then extend ActionMappingBase to provide access to this new
> property:
>
> public final class MyApplicationMapping extends ActionMappingBase {
>
>     private boolean use_default_home_page = false;
>
>     public boolean getUseDefaultHomePage() { return
> use_default_home_page; }
>     public void setUseDefaultHomePage(boolean v)
> {use_default_home_page = v; }
> }
>
> Supply the class name for your custom mapping as a init parameter for
> ActionServlet (see ActionServlet API docs) and the Struts Digester class
> will then populate MyApplicationMapping from action.xml for you.  From
> within you Action perform() method, cast the passed in ActionMapping to
> MyActionMapping, and Bob's your uncle.
>
> The example used to show this for "success" and "failure" mappings but
> Craig replaced them with the (more elegant) forward tags.
>
> Hope this helps,
>
> -jh
>
>
> --
> Jeff Hutchison <jhut@inst.strykercorp.com>
> Stryker Instruments, Kalamazoo, MI
>


Mime
View raw message