You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Craig Randall <cs...@hotmail.com> on 2000/06/20 23:33:38 UTC

action.xml attribute v elements, & specifying style

Hi, I'm fairly new to this list. Struts looks quite useful! I do have a 
couple of questions about the framework:

1. In action.xml is there a technical reason why attributes are used so 
heavily and not elements? Since the values of the current attributes may be 
quite diverse, it seems to me that elements might be a bit more appropriate, 
and in the long-run, more flexible.

2. Has any thought been given toward augmenting Struts to specify style 
(e.g. CSS) so that all forms, etc. have a consistent look-and-feel that's 
easy to change via XML?

Thanks.

-Craig Randall (csrandall@hotmail.com)
________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com


Re: Struts..latest version

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Kevin Duffey wrote:

> Hi,
>
> Just noticed..the documentation isn't up to date to explain the
> ActionForward usage..I am sure your working on this..just thought I'd point
> it out incase you weren't aware.

This got fixed today ... check tonight's nightly build.

Craig



Re: Struts..latest version

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Kevin Duffey wrote:

> Hi,
>
> Just noticed..the documentation isn't up to date to explain the
> ActionForward usage..I am sure your working on this..just thought I'd point
> it out incase you weren't aware.

This got fixed today ... check tonight's nightly build.

Craig



Struts..latest version

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

Just noticed..the documentation isn't up to date to explain the
ActionForward usage..I am sure your working on this..just thought I'd point
it out incase you weren't aware.


Re: Struts--question about bean/form name.

Posted by "Craig R. McClanahan" <Cr...@Eng.Sun.COM>.
Kevin Duffey wrote:

> Hi,
>
> is there any way in each of my action perform() methods to get the "name" of
> the bean that was set in the action.xml, so that I can use that String name
> for various purposes? For example, we don't use EJB yet, so we separate our
> logic into "logic_session" classes. These session classes are stored in the
> HttpSession, with a reference to our bean, and I would like to store them by
> using the name of the bean (form passed in) and appending "Session" to that
> name. In the JSP page I have to hardcode it though..which means I still have
> to change the bean name in two places..if I change it for any reason.
>

The perform() method of an action receives a "mapping" parameter that is the
ActionMapping instance which caused this action to be invoked.  Therefore, you
can access any of the properties of that mapping -- for example, you can
retrieve the session key under which the form bean for this action is stored, by
calling

    mapping.getFormAttribute()

in your action class.  See the next response for how to extend this capability
with your own properties.

>
> Thanks.

Craig



Re: Struts--question about bean/form name.

Posted by "Craig R. McClanahan" <Cr...@Eng.Sun.COM>.
Kevin Duffey wrote:

> Hi,
>
> is there any way in each of my action perform() methods to get the "name" of
> the bean that was set in the action.xml, so that I can use that String name
> for various purposes? For example, we don't use EJB yet, so we separate our
> logic into "logic_session" classes. These session classes are stored in the
> HttpSession, with a reference to our bean, and I would like to store them by
> using the name of the bean (form passed in) and appending "Session" to that
> name. In the JSP page I have to hardcode it though..which means I still have
> to change the bean name in two places..if I change it for any reason.
>

The perform() method of an action receives a "mapping" parameter that is the
ActionMapping instance which caused this action to be invoked.  Therefore, you
can access any of the properties of that mapping -- for example, you can
retrieve the session key under which the form bean for this action is stored, by
calling

    mapping.getFormAttribute()

in your action class.  See the next response for how to extend this capability
with your own properties.

>
> Thanks.

Craig



RE: Struts--question about bean/form name.

Posted by David Chisholm <Da...@i2.com>.
Excellent point.
David


> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> Sent: Wednesday, June 21, 2000 4:41 PM
> To: struts-dev@jakarta.apache.org
> Subject: Re: Struts--question about bean/form name.
>
>
> David Chisholm wrote:
>
> >
> > What I would like to do in the init method is configure static
> attributes of
> > the action that may come from a dynamic source like a database.
>  This could
> > be done in the constructor, but the action may need information from its
> > ActionMapping instance.
> >
> > I like the ability to define your own custom ActionMapping
> class, but it's
> > sorta like Java's single inheritance - you've only got one to
> use.  However,
> > you're instructions on adding custom rules like addForward()
> shows how to
> > add a lot flexibility to the ActionMapping.
> >
>
> You could also dispense with the idea of creating the
> ActionMapping collections
> from an XML file at all, if you wanted to.  After all, an ActionMapping
> implementation class (like ActionMappingBase) is just a JavaBean with some
> properties.  You could easily initialize them in whatever manner
> you like (such
> as loading them from a database) by overriding the initMapping()
> method, but
> still take advantage of the rest of the framework.  All you need
> to do is call
> the ActionServlet's addMapping() method so that it knows about
> the completed
> mapping beans.
>
> That is kind of why I called the thing "Struts" in the first
> place -- it is a
> bunch of small pieces that work together synergistically, but you
> should have
> the right to replace my standard yellow strut with your red one,
> without having
> to build the entire structure over again :-).
>
> >
> > David
> >
>
> Craig
>
>


Re: Struts--question about bean/form name.

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
David Chisholm wrote:

>
> What I would like to do in the init method is configure static attributes of
> the action that may come from a dynamic source like a database.  This could
> be done in the constructor, but the action may need information from its
> ActionMapping instance.
>
> I like the ability to define your own custom ActionMapping class, but it's
> sorta like Java's single inheritance - you've only got one to use.  However,
> you're instructions on adding custom rules like addForward() shows how to
> add a lot flexibility to the ActionMapping.
>

You could also dispense with the idea of creating the ActionMapping collections
from an XML file at all, if you wanted to.  After all, an ActionMapping
implementation class (like ActionMappingBase) is just a JavaBean with some
properties.  You could easily initialize them in whatever manner you like (such
as loading them from a database) by overriding the initMapping() method, but
still take advantage of the rest of the framework.  All you need to do is call
the ActionServlet's addMapping() method so that it knows about the completed
mapping beans.

That is kind of why I called the thing "Struts" in the first place -- it is a
bunch of small pieces that work together synergistically, but you should have
the right to replace my standard yellow strut with your red one, without having
to build the entire structure over again :-).

>
> David
>

Craig



RE: Struts--question about bean/form name.

Posted by David Chisholm <Da...@i2.com>.
comment at end...

> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@Eng.Sun.COM]
> Sent: Wednesday, June 21, 2000 11:22 AM
> To: struts-user@jakarta.apache.org
> Cc: struts-dev@jakarta.apache.org
> Subject: Re: Struts--question about bean/form name.
>
>
> 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>
> >
> > One suggestion, add a 'public void init(ActionMapping mapping)'
> method to
> > Action that is called when the Action is instantiated to allow
> the Action to
> > perform any static initialization that it needs, and a 'public void
> > destroy()' to allow it to do any cleanup.  ActionBase would then provide
> > default implementations of these methods.
> >
>
> The approach to non-standard attributes in ActionMappings is
> actually pretty
> cool.  It works like this (documented in the User's Guide, by the way).
>
> * Create a new class that implements ActionMapping (or extends
>   ActionMappingBase, which is usually more convenient).
>
> * In this new class, add public getter and setter methods for the
>   new properties you want to define, following JavaBeans naming
>   conventions.  The property type can be String, int, boolean, float,
>   or double.
>
> * In the action.xml file, add new attributes in the <action> element to
>   initialize the new property values.
>
> * In the web.xml file for your application, declare a servlet
> initialization
>   parameter for the controller servlet that identifies the name of the
>   ActionMapping class to be used (i.e. your new one):
>
>         <init-param>
>             <param-name>mapping</param-name>
>             <param-value>com.mycompany.MyActionMapping</param-value>
>         </init-param>
>
> * When the controller servlet starts, it will auto-magically set all the
> standard
>   ActionMapping properties, plus all of your new ones.  It uses
> Java reflection
>   to match up the property names versus the setter methods in your
>   ActionMapping class.
>
> This would seem to avoid the need to build your own init() method in an
> ActionMapping simply to configure non-standard property values.
>

What I would like to do in the init method is configure static attributes of
the action that may come from a dynamic source like a database.  This could
be done in the constructor, but the action may need information from its
ActionMapping instance.

I like the ability to define your own custom ActionMapping class, but it's
sorta like Java's single inheritance - you've only got one to use.  However,
you're instructions on adding custom rules like addForward() shows how to
add a lot flexibility to the ActionMapping.

David









> >
> > David
> >
>
> Craig McClanahan
>
>


Re: Struts--question about bean/form name.

Posted by "Craig R. McClanahan" <Cr...@Eng.Sun.COM>.
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>
>
> One suggestion, add a 'public void init(ActionMapping mapping)' method to
> Action that is called when the Action is instantiated to allow the Action to
> perform any static initialization that it needs, and a 'public void
> destroy()' to allow it to do any cleanup.  ActionBase would then provide
> default implementations of these methods.
>

The approach to non-standard attributes in ActionMappings is actually pretty
cool.  It works like this (documented in the User's Guide, by the way).

* Create a new class that implements ActionMapping (or extends
  ActionMappingBase, which is usually more convenient).

* In this new class, add public getter and setter methods for the
  new properties you want to define, following JavaBeans naming
  conventions.  The property type can be String, int, boolean, float,
  or double.

* In the action.xml file, add new attributes in the <action> element to
  initialize the new property values.

* In the web.xml file for your application, declare a servlet initialization
  parameter for the controller servlet that identifies the name of the
  ActionMapping class to be used (i.e. your new one):

        <init-param>
            <param-name>mapping</param-name>
            <param-value>com.mycompany.MyActionMapping</param-value>
        </init-param>

* When the controller servlet starts, it will auto-magically set all the
standard
  ActionMapping properties, plus all of your new ones.  It uses Java reflection
  to match up the property names versus the setter methods in your
  ActionMapping class.

This would seem to avoid the need to build your own init() method in an
ActionMapping simply to configure non-standard property values.

>
> David
>

Craig McClanahan



Re: Struts--question about bean/form name.

Posted by "Craig R. McClanahan" <Cr...@Eng.Sun.COM>.
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>
>
> One suggestion, add a 'public void init(ActionMapping mapping)' method to
> Action that is called when the Action is instantiated to allow the Action to
> perform any static initialization that it needs, and a 'public void
> destroy()' to allow it to do any cleanup.  ActionBase would then provide
> default implementations of these methods.
>

The approach to non-standard attributes in ActionMappings is actually pretty
cool.  It works like this (documented in the User's Guide, by the way).

* Create a new class that implements ActionMapping (or extends
  ActionMappingBase, which is usually more convenient).

* In this new class, add public getter and setter methods for the
  new properties you want to define, following JavaBeans naming
  conventions.  The property type can be String, int, boolean, float,
  or double.

* In the action.xml file, add new attributes in the <action> element to
  initialize the new property values.

* In the web.xml file for your application, declare a servlet initialization
  parameter for the controller servlet that identifies the name of the
  ActionMapping class to be used (i.e. your new one):

        <init-param>
            <param-name>mapping</param-name>
            <param-value>com.mycompany.MyActionMapping</param-value>
        </init-param>

* When the controller servlet starts, it will auto-magically set all the
standard
  ActionMapping properties, plus all of your new ones.  It uses Java reflection
  to match up the property names versus the setter methods in your
  ActionMapping class.

This would seem to avoid the need to build your own init() method in an
ActionMapping simply to configure non-standard property values.

>
> David
>

Craig McClanahan



Re: Struts--question about bean/form name.

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
David Chisholm wrote:

> Thanks Craig.  I had looked at the initMapping() method, but didn't
> understand what it was doing.  Your response would make a nice addition to
> the struts documentation.
> David
>

Yah, the Digester package deserve's its own users guide with a bunch of
examples.  You know how it is ... the code always seems to come before the
documentation :-).

Craig



RE: Struts--question about bean/form name.

Posted by David Chisholm <Da...@i2.com>.
Thanks Craig.  I had looked at the initMapping() method, but didn't
understand what it was doing.  Your response would make a nice addition to
the struts documentation.
David


> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@Eng.Sun.COM]
> Sent: Wednesday, June 21, 2000 12:04 PM
> To: struts-user@jakarta.apache.org
> Subject: Re: Struts--question about bean/form name.
>
>
> David Chisholm wrote:
>
> > Can you create a custom ActionMapping class that can store arbitrary
> > information?  (This doesn't appear possible.)
>
> You can in fact do this -- it becomes a little more work.  I
> followed these
> steps when I added the ability to define as many <forward>
> elements as you want
> underneath an <action>, so I will describe the steps in terms of
> that scenario:
>
> * Optionally, create a new class that represents the "thing" you are going
>   to be saving configuration in, if it's not just a simple
> string.  In my case,
>   I created a new ActionForward class to represent a logical name, a
>   corresponding path, and a redirect flag.
>
> * Create an extended ActionMapping class that includes a collection (a
>   Hashtable or HashMap, for example) for the new thing you want to add.
>   In my case, I added a Hashtable called "forwards" to ActionMappingBase.
>
> * In this custom ActionMapping method, create a new public method that
>   adds a new entry to this collection.  In my case, I added:
>         public void addForward(ActionForward forward) {
>             forwards.put(forward.getName(), forward);
>         }
>
> * Override the initMapping() method of ActionServlet with one
> that adds some
>   additional rules to the Digester that processes the XML file.
> The precise
>   details here get pretty intense -- suffice it to say that I added the
> following
>   rules:
>
>         digester.addObjectCreate("action-mappings/action/forward",
>             forwardClass);
>         digester.addSetProperties("action-mappings/action/forward");
>         digester.addSetNext("action-mappings/action/forward",
>             "addForward", "org.apache.struts.action.ActionForward");
>
>   that cause the following actions whenever a <forward> element is found
>   within an <action> element:
>
>     -   Create a new object of the class specified by the "forwardClass"
>         variable (normally "org.apache.struts.action.ActionForward")
>         and push it on the digester's stack.
>     -   On the new top stack element, map all the properties from
> the current
>         XML element (the <forward>) into corresponding setXxxx calls.
>     -   Call the addForward() method of the next-to-top element
> on the stack,
>         passing the top element of the stack as an argument.  The
> method expects
>
>         an argument of type org.apache.struts.action.ActionForward (or a
> subclass
>         of that class).
>     -   Pop the top element (the ActionForward object) off the
> digester's stack.
>
> In principle, you can do the same sort of thing for any
> arbitrarily nested set
> of XML elements to define pretty much any configuration
> information that can be
> statically represented as a tree of objects -- no loops or many-to-many
> relationships, but pretty much anything else.  For a more complex
> example of
> this same design approach, look at Tomcat's "conf/server.xml"
> file -- Tomcat
> uses a very similar approach to configure itself based on the
> contents of a very
> comprehensive configuration file.  Tomcat uses this to read the
> web.xml file
> describing your application as well.
>
> >  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?
> >
>
> A custom ActionMapping per action entry?  That seems like it
> might be reasonable
> to make a standard feature of, falling back to the default one if
> you don't
> override it.  I'll look at that scenario.
>
> >
> > David
> >
>
> Craig
>
>


Re: Struts--question about bean/form name.

Posted by "Craig R. McClanahan" <Cr...@Eng.Sun.COM>.
David Chisholm wrote:

> Can you create a custom ActionMapping class that can store arbitrary
> information?  (This doesn't appear possible.)

You can in fact do this -- it becomes a little more work.  I followed these
steps when I added the ability to define as many <forward> elements as you want
underneath an <action>, so I will describe the steps in terms of that scenario:

* Optionally, create a new class that represents the "thing" you are going
  to be saving configuration in, if it's not just a simple string.  In my case,
  I created a new ActionForward class to represent a logical name, a
  corresponding path, and a redirect flag.

* Create an extended ActionMapping class that includes a collection (a
  Hashtable or HashMap, for example) for the new thing you want to add.
  In my case, I added a Hashtable called "forwards" to ActionMappingBase.

* In this custom ActionMapping method, create a new public method that
  adds a new entry to this collection.  In my case, I added:
        public void addForward(ActionForward forward) {
            forwards.put(forward.getName(), forward);
        }

* Override the initMapping() method of ActionServlet with one that adds some
  additional rules to the Digester that processes the XML file.  The precise
  details here get pretty intense -- suffice it to say that I added the
following
  rules:

        digester.addObjectCreate("action-mappings/action/forward",
            forwardClass);
        digester.addSetProperties("action-mappings/action/forward");
        digester.addSetNext("action-mappings/action/forward",
            "addForward", "org.apache.struts.action.ActionForward");

  that cause the following actions whenever a <forward> element is found
  within an <action> element:

    -   Create a new object of the class specified by the "forwardClass"
        variable (normally "org.apache.struts.action.ActionForward")
        and push it on the digester's stack.
    -   On the new top stack element, map all the properties from the current
        XML element (the <forward>) into corresponding setXxxx calls.
    -   Call the addForward() method of the next-to-top element on the stack,
        passing the top element of the stack as an argument.  The method expects

        an argument of type org.apache.struts.action.ActionForward (or a
subclass
        of that class).
    -   Pop the top element (the ActionForward object) off the digester's stack.

In principle, you can do the same sort of thing for any arbitrarily nested set
of XML elements to define pretty much any configuration information that can be
statically represented as a tree of objects -- no loops or many-to-many
relationships, but pretty much anything else.  For a more complex example of
this same design approach, look at Tomcat's "conf/server.xml" file -- Tomcat
uses a very similar approach to configure itself based on the contents of a very
comprehensive configuration file.  Tomcat uses this to read the web.xml file
describing your application as well.

>  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?
>

A custom ActionMapping per action entry?  That seems like it might be reasonable
to make a standard feature of, falling back to the default one if you don't
override it.  I'll look at that scenario.

>
> David
>

Craig



RE: Struts--question about bean/form name.

Posted by David Chisholm <Da...@i2.com>.
Thanks for the idea.  My alternative solution is to define a custom
attribute that specifies a properties file, and then create a custom
ActionMapping to load the properties file.  The benefit of this is that it
keeps the action’s custom properties in the ActionMapping, but at the cost
of lots of small configuration files.

Perhaps I will combine the two ideas: A single extended configuration file
and a custom ActionMapping that extracts only its Action’s custom properties
from this file and stores them in the ActionMapping instance.

David


> -----Original Message-----
> From: jhut@inst.strykercorp.com [mailto:jhut@inst.strykercorp.com]
> Sent: Wednesday, June 21, 2000 9:01 AM
> To: struts-user@jakarta.apache.org
> Subject: RE: Struts--question about bean/form name.
>
>
> On Wed, 21 Jun 2000, David Chisholm wrote:
>
> > 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.
>
> This type of general purpose Action configuration data may be outside of
> the scope of what ActionMapping was designed for.  In any case, you could
> put an instance of the HashMap containing Action configuration information
> in the servlet context.  For the key, you could concatenate the action
> class name with the configuration parameter name to accomodate any number
> of actions.  Just load the hashmap (from something like a properties or
> xml file) at application initialization time with a load-on-startup
> servlet class (cf. DatabaseServlet in the example).  A simple approach,
> but it might serve your needs.
>
> >
> > David
>
> -jh
>
> --
> Jeff Hutchison <jh...@inst.strykercorp.com>
> Stryker Instruments, Kalamazoo, MI
>


RE: Struts--question about bean/form name.

Posted by jh...@inst.strykercorp.com.
On Wed, 21 Jun 2000, David Chisholm wrote:

> 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.

This type of general purpose Action configuration data may be outside of
the scope of what ActionMapping was designed for.  In any case, you could
put an instance of the HashMap containing Action configuration information
in the servlet context.  For the key, you could concatenate the action
class name with the configuration parameter name to accomodate any number
of actions.  Just load the hashmap (from something like a properties or
xml file) at application initialization time with a load-on-startup
servlet class (cf. DatabaseServlet in the example).  A simple approach,
but it might serve your needs.
 
> 
> David

-jh

-- 
Jeff Hutchison <jh...@inst.strykercorp.com>
Stryker Instruments, Kalamazoo, MI


Re: Struts--question about bean/form name.

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Kevin Duffey wrote:

> Hi,
>
> I would say..use the source, and modify the actual source in some way for
> your needs. The downside is..as Craig updates the builds..you'll have to
> keep modifying the code again and again. Unless..you just make a hook call
> from inside the Struts source. Then you simply add that call to each new
> build, and paste in your method that handles whatever it is you need. I
> built the source and added a bunch of out.printlns because I was having
> problems with JDK1.3 and Orion..thus how I learned about the JDK 1.3 bug
> with resource bundles.

For customizations that are less fragile, you can also subclass ActionServlet
and override the methods that do the specific functionality you want to
change.  For example, if you wanted to do something special before and after
the usual call to the action class, you could do this:

    public class MyActionServlet extends ActionServlet {

        protected void processActionInstance(ActionMapping mapping,
            ActionForm formInstance, HttpServletRequest request,
            HttpServletResponse response)
                throws IOException, ServletException {

            doMyPreprocessing();
            super.processActionInstance(mapping, formInstance,
              request, response);
            doMyPostprocessing();

        }

    }

which will survive changes in the underlying code as long as the method
signatures are not changed.

At the moment, we're still in a little bit of flux as we accumulate and
implement all the good ideas that have been suggested.  Once a 1.0 release
occurs, incompatible changes to the method signatures will be avoided if at
all possible, to maintain backwards compatibility of customizations like the
one above.

Craig McClanahan





RE: Struts--question about bean/form name.

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

I would say..use the source, and modify the actual source in some way for
your needs. The downside is..as Craig updates the builds..you'll have to
keep modifying the code again and again. Unless..you just make a hook call
from inside the Struts source. Then you simply add that call to each new
build, and paste in your method that handles whatever it is you need. I
built the source and added a bunch of out.printlns because I was having
problems with JDK1.3 and Orion..thus how I learned about the JDK 1.3 bug
with resource bundles.



RE: Struts--question about bean/form name.

Posted by David Chisholm <Da...@i2.com>.
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 <jh...@inst.strykercorp.com>
> Stryker Instruments, Kalamazoo, MI
>


RE: Struts--question about bean/form name.

Posted by jh...@inst.strykercorp.com.
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 <jh...@inst.strykercorp.com>
Stryker Instruments, Kalamazoo, MI


RE: Struts--question about bean/form name.

Posted by David Chisholm <Da...@i2.com>.
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>


One suggestion, add a 'public void init(ActionMapping mapping)' method to
Action that is called when the Action is instantiated to allow the Action to
perform any static initialization that it needs, and a 'public void
destroy()' to allow it to do any cleanup.  ActionBase would then provide
default implementations of these methods.

David


> -----Original Message-----
> From: Kevin Duffey [mailto:kduffey@buymedia.com]
> Sent: Wednesday, June 21, 2000 1:09 AM
> To: struts-user@jakarta.apache.org
> Cc: struts-dev@jakarta.apache.org
> Subject: Struts--question about bean/form name.
>
>
> Hi,
>
> is there any way in each of my action perform() methods to get
> the "name" of
> the bean that was set in the action.xml, so that I can use that
> String name
> for various purposes? For example, we don't use EJB yet, so we
> separate our
> logic into "logic_session" classes. These session classes are
> stored in the
> HttpSession, with a reference to our bean, and I would like to
> store them by
> using the name of the bean (form passed in) and appending
> "Session" to that
> name. In the JSP page I have to hardcode it though..which means I
> still have
> to change the bean name in two places..if I change it for any reason.
>
> Thanks.
>


RE: Struts--question about bean/form name.

Posted by David Chisholm <Da...@i2.com>.
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>


One suggestion, add a 'public void init(ActionMapping mapping)' method to
Action that is called when the Action is instantiated to allow the Action to
perform any static initialization that it needs, and a 'public void
destroy()' to allow it to do any cleanup.  ActionBase would then provide
default implementations of these methods.

David


> -----Original Message-----
> From: Kevin Duffey [mailto:kduffey@buymedia.com]
> Sent: Wednesday, June 21, 2000 1:09 AM
> To: struts-user@jakarta.apache.org
> Cc: struts-dev@jakarta.apache.org
> Subject: Struts--question about bean/form name.
>
>
> Hi,
>
> is there any way in each of my action perform() methods to get
> the "name" of
> the bean that was set in the action.xml, so that I can use that
> String name
> for various purposes? For example, we don't use EJB yet, so we
> separate our
> logic into "logic_session" classes. These session classes are
> stored in the
> HttpSession, with a reference to our bean, and I would like to
> store them by
> using the name of the bean (form passed in) and appending
> "Session" to that
> name. In the JSP page I have to hardcode it though..which means I
> still have
> to change the bean name in two places..if I change it for any reason.
>
> Thanks.
>


Struts--question about bean/form name.

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

is there any way in each of my action perform() methods to get the "name" of
the bean that was set in the action.xml, so that I can use that String name
for various purposes? For example, we don't use EJB yet, so we separate our
logic into "logic_session" classes. These session classes are stored in the
HttpSession, with a reference to our bean, and I would like to store them by
using the name of the bean (form passed in) and appending "Session" to that
name. In the JSP page I have to hardcode it though..which means I still have
to change the bean name in two places..if I change it for any reason.

Thanks.


Struts - latest build - possible change

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

Craig,

In the ActionServlet class, I recommend a "minor" change...


    protected boolean processValidate(ActionMapping mapping,
        ActionForm formInstance, HttpServletRequest request,
        HttpServletResponse response)
        throws IOException, ServletException {

	// Skip validation if it is not appropriate
	if (formInstance == null)
	    return (true);
	if (!(formInstance instanceof ValidatingActionForm))
	    return (true);
	if (mapping.getInputForm() == null)
	    return (true);

	// Perform the requested validation
	if (debug >= 1)
	    log(" Validating bean properties");
	String errors[] = ((ValidatingActionForm) formInstance).validate();
	if ((errors == null) || (errors.length == 0))
	    return (true);

	// Save our error messages and return to the input form
	String uri = mapping.getInputForm();
	if (debug >= 1)
	    log(" Form validation error: redirecting to: " + uri);
	request.setAttribute(Action.ERROR_KEY, errors);
	RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
	rd.forward(request, response);
	return (false);

    }


in this method, possibly add the ability to response.sendRedirect() to the
page, like you do in the process() call for ActionForward (true/false for
forward/redirect).


Yeah/Nay?


Struts--question about bean/form name.

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

is there any way in each of my action perform() methods to get the "name" of
the bean that was set in the action.xml, so that I can use that String name
for various purposes? For example, we don't use EJB yet, so we separate our
logic into "logic_session" classes. These session classes are stored in the
HttpSession, with a reference to our bean, and I would like to store them by
using the name of the bean (form passed in) and appending "Session" to that
name. In the JSP page I have to hardcode it though..which means I still have
to change the bean name in two places..if I change it for any reason.

Thanks.


Struts..latest version

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

Just noticed..the documentation isn't up to date to explain the
ActionForward usage..I am sure your working on this..just thought I'd point
it out incase you weren't aware.


Re: Struts - latest build

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Craig R. McClanahan" wrote:

> [snip]
> If you use the new capabilities of the action.xml method (the <forward>
> element), you can set up a set of logical mappings that you can just look up,
> instead of having to create one every time.  See the usage in the example
> application -- for example, LogonAction does this when it sees a successful user
> authentication:
>
>     return (mapping.findForward("success"));
>
> which returns the configured mapping for the logical name "forward" that was set
> up at initialization time.
>

Actually, that's the logical name "success" rather than the logical name "forward".

I didn't mention one other new feature in tonight's build -- you can declare global
<forward> declarations for the entire application as well as local <forward>
declarations relevant to a particular mapping.  This is useful for things like the
mapping to the logon page, which might be required from pretty much anywhere.  See
the example app for an example of this usage.

Craig



Re: Struts - latest build

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
"Craig R. McClanahan" wrote:

> [snip]
> If you use the new capabilities of the action.xml method (the <forward>
> element), you can set up a set of logical mappings that you can just look up,
> instead of having to create one every time.  See the usage in the example
> application -- for example, LogonAction does this when it sees a successful user
> authentication:
>
>     return (mapping.findForward("success"));
>
> which returns the configured mapping for the logical name "forward" that was set
> up at initialization time.
>

Actually, that's the logical name "success" rather than the logical name "forward".

I didn't mention one other new feature in tonight's build -- you can declare global
<forward> declarations for the entire application as well as local <forward>
declarations relevant to a particular mapping.  This is useful for things like the
mapping to the logon page, which might be required from pretty much anywhere.  See
the example app for an example of this usage.

Craig



Re: Struts - latest build

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Kevin Duffey wrote:

> Hi,
>
> Sorry..posted this to the wrong subject in the group...trying again. If your
> reading this twice..I apologize for the mixup.
>
> I just downloaded the latest Struts. Damned if Craig implemented my
> suggestion! The ActionForward class for a return type from perform(). The
> only downside is..all my actions now have to be edited to return this type.
> Other than that..pretty kewl.
>
> So question to Craig...first, does each of my actions need to create a new
> ActionForward object, and populate it, then return that to use the
> forwarding capability that I assume is worked into ActionServlet (is it?).
>

If you use the new capabilities of the action.xml method (the <forward>
element), you can set up a set of logical mappings that you can just look up,
instead of having to create one every time.  See the usage in the example
application -- for example, LogonAction does this when it sees a successful user
authentication:

    return (mapping.findForward("success"));

which returns the configured mapping for the logical name "forward" that was set
up at initialization time.

>
> A thought..return an Object type, instead of ActionForward. In
> ActionServlet, use instanceof to see if it is of type String. If it
> is..forward to that page. If not, check if it is of type ActionForward..and
> if so..typecast it and use that object. The reason I ask for this is..its
> often nice to just return a String of the page to forward to, instead of
> having to create a new object then return that. While returning a string
> creates a new object, its a bit less code for every action to just return
> the String.
>

The reason it returns ActionForward instead of String is -- at the suggestion of
someone else on the list -- sometimes you want to forward and sometimes you want
to redirect.  The ActionForward object lets you specify both the destination URL
and the redirect flag.

In ActionServlet, the current implementation looks like this:

    ActionForward forward =
        actionInstance.perform(this, mapping, formInstance,
            request, response);
    if (forward != null) {
        String path = forward.getPath();
        if (forward.getRedirect())
            response.sendRedirect(path);
        else {
            RequestDispatcher rd =
                getServletContext().getRequestDispatcher(path);
            rd.forward(request, response);
        }
    }

so if you want to redirect instead of forward, set your <forward> entry up like
this:

    <forward name="success" path="logon.jsp" redirect="true"/>

and that will happen for you (this also answers your second email question about
whether Struts can redirect instead of forward).

>
> Ofcourse..I would much rather use a "mapping" in the action.xml file, which
> I see you added as well..so that I can just have a lookup done based on the
> action being called. But I am not quite sure how that works. Do I still need
> to create an ActionForward object, populate only the "forward" name, and the
> ActionServlet checks to see if the relative path is empty..if so, do a
> lookup on the name from the action, or what?
>

See the example application, and the discussion above.

>
> A feature request:
>
>   Ability to NOT use the international classes, via an init param. In other
> words, conditionalize the use of a resource bundle, getMessage() calls, etc.
> That way..if my app is strictly US bound, I don't have to worry about the
> JDK 1.3 bug with ResourceBundle that apparently exists, so that I can run my
> code under JDK 1.3. I found out that Orion works fine with Struts, except
> when running Orion under JDK 1.3, because there is a bug in JDK 1.3
> assocated with the getResourceBundle() call or something. Is this true?
>

I will look at the implications of this.

>
> Thanks.

Craig



Re: Struts - latest build

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Kevin Duffey wrote:

> Hi,
>
> Sorry..posted this to the wrong subject in the group...trying again. If your
> reading this twice..I apologize for the mixup.
>
> I just downloaded the latest Struts. Damned if Craig implemented my
> suggestion! The ActionForward class for a return type from perform(). The
> only downside is..all my actions now have to be edited to return this type.
> Other than that..pretty kewl.
>
> So question to Craig...first, does each of my actions need to create a new
> ActionForward object, and populate it, then return that to use the
> forwarding capability that I assume is worked into ActionServlet (is it?).
>

If you use the new capabilities of the action.xml method (the <forward>
element), you can set up a set of logical mappings that you can just look up,
instead of having to create one every time.  See the usage in the example
application -- for example, LogonAction does this when it sees a successful user
authentication:

    return (mapping.findForward("success"));

which returns the configured mapping for the logical name "forward" that was set
up at initialization time.

>
> A thought..return an Object type, instead of ActionForward. In
> ActionServlet, use instanceof to see if it is of type String. If it
> is..forward to that page. If not, check if it is of type ActionForward..and
> if so..typecast it and use that object. The reason I ask for this is..its
> often nice to just return a String of the page to forward to, instead of
> having to create a new object then return that. While returning a string
> creates a new object, its a bit less code for every action to just return
> the String.
>

The reason it returns ActionForward instead of String is -- at the suggestion of
someone else on the list -- sometimes you want to forward and sometimes you want
to redirect.  The ActionForward object lets you specify both the destination URL
and the redirect flag.

In ActionServlet, the current implementation looks like this:

    ActionForward forward =
        actionInstance.perform(this, mapping, formInstance,
            request, response);
    if (forward != null) {
        String path = forward.getPath();
        if (forward.getRedirect())
            response.sendRedirect(path);
        else {
            RequestDispatcher rd =
                getServletContext().getRequestDispatcher(path);
            rd.forward(request, response);
        }
    }

so if you want to redirect instead of forward, set your <forward> entry up like
this:

    <forward name="success" path="logon.jsp" redirect="true"/>

and that will happen for you (this also answers your second email question about
whether Struts can redirect instead of forward).

>
> Ofcourse..I would much rather use a "mapping" in the action.xml file, which
> I see you added as well..so that I can just have a lookup done based on the
> action being called. But I am not quite sure how that works. Do I still need
> to create an ActionForward object, populate only the "forward" name, and the
> ActionServlet checks to see if the relative path is empty..if so, do a
> lookup on the name from the action, or what?
>

See the example application, and the discussion above.

>
> A feature request:
>
>   Ability to NOT use the international classes, via an init param. In other
> words, conditionalize the use of a resource bundle, getMessage() calls, etc.
> That way..if my app is strictly US bound, I don't have to worry about the
> JDK 1.3 bug with ResourceBundle that apparently exists, so that I can run my
> code under JDK 1.3. I found out that Orion works fine with Struts, except
> when running Orion under JDK 1.3, because there is a bug in JDK 1.3
> assocated with the getResourceBundle() call or something. Is this true?
>

I will look at the implications of this.

>
> Thanks.

Craig



Struts - latest build

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

Sorry..posted this to the wrong subject in the group...trying again. If your
reading this twice..I apologize for the mixup.


I just downloaded the latest Struts. Damned if Craig implemented my
suggestion! The ActionForward class for a return type from perform(). The
only downside is..all my actions now have to be edited to return this type.
Other than that..pretty kewl.

So question to Craig...first, does each of my actions need to create a new
ActionForward object, and populate it, then return that to use the
forwarding capability that I assume is worked into ActionServlet (is it?).

A thought..return an Object type, instead of ActionForward. In
ActionServlet, use instanceof to see if it is of type String. If it
is..forward to that page. If not, check if it is of type ActionForward..and
if so..typecast it and use that object. The reason I ask for this is..its
often nice to just return a String of the page to forward to, instead of
having to create a new object then return that. While returning a string
creates a new object, its a bit less code for every action to just return
the String.

Ofcourse..I would much rather use a "mapping" in the action.xml file, which
I see you added as well..so that I can just have a lookup done based on the
action being called. But I am not quite sure how that works. Do I still need
to create an ActionForward object, populate only the "forward" name, and the
ActionServlet checks to see if the relative path is empty..if so, do a
lookup on the name from the action, or what?


A feature request:

  Ability to NOT use the international classes, via an init param. In other
words, conditionalize the use of a resource bundle, getMessage() calls, etc.
That way..if my app is strictly US bound, I don't have to worry about the
JDK 1.3 bug with ResourceBundle that apparently exists, so that I can run my
code under JDK 1.3. I found out that Orion works fine with Struts, except
when running Orion under JDK 1.3, because there is a bug in JDK 1.3
assocated with the getResourceBundle() call or something. Is this true?


Thanks.


Struts - latest build

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

Sorry..posted this to the wrong subject in the group...trying again. If your
reading this twice..I apologize for the mixup.


I just downloaded the latest Struts. Damned if Craig implemented my
suggestion! The ActionForward class for a return type from perform(). The
only downside is..all my actions now have to be edited to return this type.
Other than that..pretty kewl.

So question to Craig...first, does each of my actions need to create a new
ActionForward object, and populate it, then return that to use the
forwarding capability that I assume is worked into ActionServlet (is it?).

A thought..return an Object type, instead of ActionForward. In
ActionServlet, use instanceof to see if it is of type String. If it
is..forward to that page. If not, check if it is of type ActionForward..and
if so..typecast it and use that object. The reason I ask for this is..its
often nice to just return a String of the page to forward to, instead of
having to create a new object then return that. While returning a string
creates a new object, its a bit less code for every action to just return
the String.

Ofcourse..I would much rather use a "mapping" in the action.xml file, which
I see you added as well..so that I can just have a lookup done based on the
action being called. But I am not quite sure how that works. Do I still need
to create an ActionForward object, populate only the "forward" name, and the
ActionServlet checks to see if the relative path is empty..if so, do a
lookup on the name from the action, or what?


A feature request:

  Ability to NOT use the international classes, via an init param. In other
words, conditionalize the use of a resource bundle, getMessage() calls, etc.
That way..if my app is strictly US bound, I don't have to worry about the
JDK 1.3 bug with ResourceBundle that apparently exists, so that I can run my
code under JDK 1.3. I found out that Orion works fine with Struts, except
when running Orion under JDK 1.3, because there is a bug in JDK 1.3
assocated with the getResourceBundle() call or something. Is this true?


Thanks.


RE: action.xml attribute v elements, & specifying style

Posted by Kevin Duffey <kd...@buymedia.com>.
Hi,

I just downloaded the latest Struts. Damned if Craig implemented my
suggestion! The ActionForward class for a return type from perform(). The
only downside is..all my actions now have to be edited to return this type.
Other than that..pretty kewl.

So question to Craig...first, does each of my actions need to create a new
ActionForward object, and populate it, then return that to use the
forwarding capability that I assume is worked into ActionServlet (is it?).

A thought..return an Object type, instead of ActionForward. In
ActionServlet, use instanceof to see if it is of type String. If it
is..forward to that page. If not, check if it is of type ActionForward..and
if so..typecast it and use that object. The reason I ask for this is..its
often nice to just return a String of the page to forward to, instead of
having to create a new object then return that. While returning a string
creates a new object, its a bit less code for every action to just return
the String.

Ofcourse..I would much rather use a "mapping" in the action.xml file, which
I see you added as well..so that I can just have a lookup done based on the
action being called. But I am not quite sure how that works. Do I still need
to create an ActionForward object, populate only the "forward" name, and the
ActionServlet checks to see if the relative path is empty..if so, do a
lookup on the name from the action, or what?


A feature request:

  Ability to NOT use the international classes, via an init param. In other
words, conditionalize the use of a resource bundle, getMessage() calls, etc.
That way..if my app is strictly US bound, I don't have to worry about the
JDK 1.3 bug with ResourceBundle that apparently exists, so that I can run my
code under JDK 1.3. I found out that Orion works fine with Struts, except
when running Orion under JDK 1.3, because there is a bug in JDK 1.3
assocated with the getResourceBundle() call or something. Is this true?


Thanks.


Re: action.xml attribute v elements, & specifying style

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Hi Craig ... cool name by the way :-)

Craig Randall wrote:

> Hi, I'm fairly new to this list. Struts looks quite useful! I do have a
> couple of questions about the framework:
>
> 1. In action.xml is there a technical reason why attributes are used so
> heavily and not elements? Since the values of the current attributes may be
> quite diverse, it seems to me that elements might be a bit more appropriate,
> and in the long-run, more flexible.
>

The syntax being used grows out of a pattern popularized in the Ant and Tomcat
tools for configuring complex sets of Java objects.  Boiled down to a nutshell,
this style tends to use an XML element to represent a Java object, and XML
attributes to represent the properties of that object, with one-to-many
relationships between objects represented by element nesting.   For the
attributes==properties scenario, Struts includes a capability (in the Digester
package) to match up attributes to the corresponding property names, without
having to be explicit about which ones you are updating, and set them all in one
fell swoop.  In Struts, one of the things this style lets you do is extend the
ActionMapping interface (or subclass the ActionForward class) and add some new
properties -- and the configuration setup will set all the new properties for
you with *no* changes to the code itself.  It's all done by reflection and name
matching.

One of the downsides to this approach is that you cannot specify a DTD for the
action.xml file -- because there is no fixed set of attributes that are legal.
This doesn't stop you from building an application-specific DTD for your own
scenario, though.

> 2. Has any thought been given toward augmenting Struts to specify style
> (e.g. CSS) so that all forms, etc. have a consistent look-and-feel that's
> easy to change via XML?
>

Recently, an optional "style" attribute was added to all of the relevant Struts
custom tags, so that you can specify your own style attributes.  In addition,
the optional "styleClass" attribute generates a "class=" reference to an
internal or external stylesheet.

>
> Thanks.

> -Craig Randall (csrandall@hotmail.com)
>

Craig McClanahan



Re: action.xml attribute v elements, & specifying style

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Hi Craig ... cool name by the way :-)

Craig Randall wrote:

> Hi, I'm fairly new to this list. Struts looks quite useful! I do have a
> couple of questions about the framework:
>
> 1. In action.xml is there a technical reason why attributes are used so
> heavily and not elements? Since the values of the current attributes may be
> quite diverse, it seems to me that elements might be a bit more appropriate,
> and in the long-run, more flexible.
>

The syntax being used grows out of a pattern popularized in the Ant and Tomcat
tools for configuring complex sets of Java objects.  Boiled down to a nutshell,
this style tends to use an XML element to represent a Java object, and XML
attributes to represent the properties of that object, with one-to-many
relationships between objects represented by element nesting.   For the
attributes==properties scenario, Struts includes a capability (in the Digester
package) to match up attributes to the corresponding property names, without
having to be explicit about which ones you are updating, and set them all in one
fell swoop.  In Struts, one of the things this style lets you do is extend the
ActionMapping interface (or subclass the ActionForward class) and add some new
properties -- and the configuration setup will set all the new properties for
you with *no* changes to the code itself.  It's all done by reflection and name
matching.

One of the downsides to this approach is that you cannot specify a DTD for the
action.xml file -- because there is no fixed set of attributes that are legal.
This doesn't stop you from building an application-specific DTD for your own
scenario, though.

> 2. Has any thought been given toward augmenting Struts to specify style
> (e.g. CSS) so that all forms, etc. have a consistent look-and-feel that's
> easy to change via XML?
>

Recently, an optional "style" attribute was added to all of the relevant Struts
custom tags, so that you can specify your own style attributes.  In addition,
the optional "styleClass" attribute generates a "class=" reference to an
internal or external stylesheet.

>
> Thanks.

> -Craig Randall (csrandall@hotmail.com)
>

Craig McClanahan