Ah, sorry I read that doc but didn't understand it until you pointed it
out. Perfect! Time to upgrade to 1.2 I suppose.
Thanks,
Erik
Jim Barrows wrote:
-----Original Message-----
From: Erik Weber [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 14, 2004 4:15 PM
To: Struts Users Mailing List
Subject: Re: Question concerning struts-config and app constants
Thanks Joe, that is indeed what I am doing. I am handling a
few actions
in a single Action class, but parameterizing on my own rather
than using
the MappingDispatchAction. The reason is that the O'Reilly
Struts book
led me to believe that if you want to use the DispatchAction
class, or
the LookupDispatchAction class, you have to put the "method"
parameter
into your requests. Please correct me if that is wrong. But I
don't like
that. Is the MappingDispatchAction different from those (my
book doesn't
seem to cover it)? I prefer to use a switch (the if-else block you
describe), to the chagrin of the OO purists, if it means I
can keep the
Well.... from the javadocs for public class MappingDispatchAction:
To configure the use of this action in your struts-config.xml file, create an entry
like this:
<action path="/saveSubscription"
type="org.example.SubscriptionAction"
name="subscriptionForm"
scope="request"
input="/subscription.jsp"
parameter="method"/>
where 'method' is the name of a method in your subclass of MappingDispatchAction that
has the same signature (other than method name) of the standard Action.execute method.
Nothing in the there about the URL.... so yes you could use it for what you want to.
You can look at the javadocs yourself and see a better example of how it works.
URLs the user sees looking the way I want (I never much liked query
strings). My Action classes are not so course-grained as to
become error
prone -- my parameter values are the likes of "add", "update"
and "delete".
What do you think?
Thanks,
Erik
Joe Germuska wrote:
> I am parameterizing an Action via the "parameter"
attribute to the
action element in struts-config.xml. The Java code in
the Action class
refers to the possible parameter values using String
constants instead
of using literal values. However, these same parameter
values are
simply
hardcoded in struts-config.xml. So if I change the values of the
constants, I have to change struts-config.xml, and
vice-versa. Is
there
> an easy way to have the values for these constants in one place?
If you describe somewhat more what you're doing with the parameters
inside the action, we might be able to suggest an alternative
implementation. For example, if you're doing some kind of
conditional
checking:
if (MY_CONSTANT1.equals(mapping.getParameter())) { ... }
else if (MY_CONSTANT2.equals(mapping.getParameter())) { ... }
you might instead be able to use the MappingDispatchAction, which
would encode the Java side of your values as method names
instead of
as String constants and eliminate the need to test the parameter
against the constant.
http://struts.apache.org/api/org/apache/struts/actions/MappingDispatchAction.html
Joe
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]