Re: Configuration for Action

2001-06-22 Thread Craig R. McClanahan



On Fri, 22 Jun 2001, Yuriy Zubarev wrote:

> Hello Craig,
> 
> First option turns out to be a great way to store
> initialization parameters that are shared by many
> actions. In this case what name convention should
> be adopted?
> 

For options that are specific to a particular Action class (say,
com.mycompany.mypackage.MyAction), I would use names like:

  com.mycompany.mypackage.MyAction.foo

for the "foo" parameter.

For initialization parameters shared by a number of different actions,
presumably the actions are related to each other.  Therefore, you might
place them all in the same Java package, and use the package name as the
prefix (so the "foo" parameter shared by all actions in the package might 
be named "com.mycompany.mypackage.foo" instead).

>From a technical perspective, it really does not matter what convention
you adopt.  However, using rules like this accomplish two good things:
* Avoids the potential for name clashes where more than one Action
  has a parameter named "foo".
* Makes the complete parameter name predictable, to reduce
  mistakes.

> Best of luck,
> Yuriy Zubarev
> 
> 

Craig


> --- "Craig R. McClanahan" <[EMAIL PROTECTED]> wrote:
> > First, one approach is to use servlet initialization parameters, and
> > adopt
> > the convention that the names of parameters for a specific action start
> > with the fully qualified class name of that action.
> > 
> > Second, if you only need *one* configuration parameter, there is a
> > general
> > purpose property of an ActionMapping called "parameter" (with accessor
> > methods getParameter() and setParameter()) that you can use for this
> > purpose.
> > 
> > Third, there is a way to store Action-specific configuration information
> > in struts-config.xml.  It's a little involved, but goes basically like
> > this:
> > 
> > * Write your own subclass of ActionMapping that includes the extra
> >   properties you are interested in.  You can do individual subclasses
> >   for each different action, or a class that includes all the custom
> >   properties you might want for any action.
> > 
> > * Modify your  entries in two respects:
> >   - Tell Struts to use your ActionMapping subclass instead of the
> > standard one.
> >   - Configure the extra parameters with  elements>
> > 
> >  >className="com.mycompany.MyActionMapping"
> > type="com.mycompany.MyAction"
> > ... >
> >   
> >   
> > 
> > 
> > * In your Action, cast the mapping you receive to your own class
> >   so you can access these extra properties:
> > 
> > public ActionForward perform(...) {
> > 
> >   MyActionMapping myMapping = (MyActionMapping) mapping;
> >   String foo = myMapping.getFoo();
> >   String bar = myMapping.getBar();
> >   ... use foo and bar to modify the behavior ...
> > 
> > }
> > 
> > Craig McClanahan
> > 
> > 
> > On Thu, 21 Jun 2001, Yuriy Zubarev wrote:
> > 
> > > Hello everybody,
> > > 
> > > While working directly with servlets, in configuration
> > > file you can specify initial valus of parameters for a servlet
> > > in the following way:
> > > 
> > > 
> > >   
> > > parameter
> > >   
> > >   
> > > value
> > >   
> > > 
> > > 
> > > And you can easily get those values without resorting to
> > > parse information on your own.
> > > 
> > > So I was wondering if it's possible to make such a
> > > thing with actions in struts-config.xml file.
> > > In another words I would like to have some custom
> > > parameters for some actions with handy means of
> > > extracting those parameters.
> > > 
> > > Thank you for your time.
> > > 
> > > Best of luck,
> > > Yuriy Zubarev
> > > 
> > > 
> > > __
> > > Do You Yahoo!?
> > > Get personalized email addresses from Yahoo! Mail
> > > http://personal.mail.yahoo.com/
> > > 
> > 
> 
> 
> __
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
> 




Re: Configuration for Action

2001-06-22 Thread Yuriy Zubarev

Hello Craig,

First option turns out to be a great way to store
initialization parameters that are shared by many
actions. In this case what name convention should
be adopted?

Best of luck,
Yuriy Zubarev


--- "Craig R. McClanahan" <[EMAIL PROTECTED]> wrote:
> First, one approach is to use servlet initialization parameters, and
> adopt
> the convention that the names of parameters for a specific action start
> with the fully qualified class name of that action.
> 
> Second, if you only need *one* configuration parameter, there is a
> general
> purpose property of an ActionMapping called "parameter" (with accessor
> methods getParameter() and setParameter()) that you can use for this
> purpose.
> 
> Third, there is a way to store Action-specific configuration information
> in struts-config.xml.  It's a little involved, but goes basically like
> this:
> 
> * Write your own subclass of ActionMapping that includes the extra
>   properties you are interested in.  You can do individual subclasses
>   for each different action, or a class that includes all the custom
>   properties you might want for any action.
> 
> * Modify your  entries in two respects:
>   - Tell Struts to use your ActionMapping subclass instead of the
> standard one.
>   - Configure the extra parameters with  elements>
> 
> className="com.mycompany.MyActionMapping"
> type="com.mycompany.MyAction"
> ... >
>   
>   
> 
> 
> * In your Action, cast the mapping you receive to your own class
>   so you can access these extra properties:
> 
> public ActionForward perform(...) {
> 
>   MyActionMapping myMapping = (MyActionMapping) mapping;
>   String foo = myMapping.getFoo();
>   String bar = myMapping.getBar();
>   ... use foo and bar to modify the behavior ...
> 
> }
> 
> Craig McClanahan
> 
> 
> On Thu, 21 Jun 2001, Yuriy Zubarev wrote:
> 
> > Hello everybody,
> > 
> > While working directly with servlets, in configuration
> > file you can specify initial valus of parameters for a servlet
> > in the following way:
> > 
> > 
> >   
> > parameter
> >   
> >   
> > value
> >   
> > 
> > 
> > And you can easily get those values without resorting to
> > parse information on your own.
> > 
> > So I was wondering if it's possible to make such a
> > thing with actions in struts-config.xml file.
> > In another words I would like to have some custom
> > parameters for some actions with handy means of
> > extracting those parameters.
> > 
> > Thank you for your time.
> > 
> > Best of luck,
> > Yuriy Zubarev
> > 
> > 
> > __
> > Do You Yahoo!?
> > Get personalized email addresses from Yahoo! Mail
> > http://personal.mail.yahoo.com/
> > 
> 


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Re: Configuration for Action

2001-06-21 Thread Craig R. McClanahan

First, one approach is to use servlet initialization parameters, and adopt
the convention that the names of parameters for a specific action start
with the fully qualified class name of that action.

Second, if you only need *one* configuration parameter, there is a general
purpose property of an ActionMapping called "parameter" (with accessor
methods getParameter() and setParameter()) that you can use for this
purpose.

Third, there is a way to store Action-specific configuration information
in struts-config.xml.  It's a little involved, but goes basically like
this:

* Write your own subclass of ActionMapping that includes the extra
  properties you are interested in.  You can do individual subclasses
  for each different action, or a class that includes all the custom
  properties you might want for any action.

* Modify your  entries in two respects:
  - Tell Struts to use your ActionMapping subclass instead of the
standard one.
  - Configure the extra parameters with  elements>


  
  


* In your Action, cast the mapping you receive to your own class
  so you can access these extra properties:

public ActionForward perform(...) {

  MyActionMapping myMapping = (MyActionMapping) mapping;
  String foo = myMapping.getFoo();
  String bar = myMapping.getBar();
  ... use foo and bar to modify the behavior ...

}

Craig McClanahan


On Thu, 21 Jun 2001, Yuriy Zubarev wrote:

> Hello everybody,
> 
> While working directly with servlets, in configuration
> file you can specify initial valus of parameters for a servlet
> in the following way:
> 
> 
>   
> parameter
>   
>   
> value
>   
> 
> 
> And you can easily get those values without resorting to
> parse information on your own.
> 
> So I was wondering if it's possible to make such a
> thing with actions in struts-config.xml file.
> In another words I would like to have some custom
> parameters for some actions with handy means of
> extracting those parameters.
> 
> Thank you for your time.
> 
> Best of luck,
> Yuriy Zubarev
> 
> 
> __
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/
> 




Re: Configuration for Action

2001-06-21 Thread Yuriy Zubarev

Mike,

Thanks for reply. But what if my servlet container is Tomcat?

And I would like to ask people how they store and retrieve
values needed to run web-apllication in genereal (except db
processing). For example, many of my actions require unique parameters,
but some share the configuration. I'm just looking for an easy way to
adopt.

Thank yo for your time.

Best of luck,
Yuriy Zubarev


--- Mike Thompson <[EMAIL PROTECTED]> wrote:
> If your running in a J2EE container, you could always shove the entries
> into
> the environment.  Then you could look them up like:
> 
> try
> {
> InitialContext ic = new InitialContext();
> Object myparm = ic.lookup("the/jndi/name/of/your/parameter");
> }
> catch (javax.naming.NamingException ex)
> {
> //uh oh, error
> }
> 
> - Original Message -
> From: "Yuriy Zubarev" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Thursday, June 21, 2001 2:09 PM
> Subject: Configuration for Action
> 
> 
> > Hello everybody,
> >
> > While working directly with servlets, in configuration
> > file you can specify initial valus of parameters for a servlet
> > in the following way:
> >
> > 
> >   
> > parameter
> >   
> >   
> > value
> >   
> > 
> >
> > And you can easily get those values without resorting to
> > parse information on your own.
> >
> > So I was wondering if it's possible to make such a
> > thing with actions in struts-config.xml file.
> > In another words I would like to have some custom
> > parameters for some actions with handy means of
> > extracting those parameters.
> >
> > Thank you for your time.
> >
> > Best of luck,
> > Yuriy Zubarev
> >
> >
> > __
> > Do You Yahoo!?
> > Get personalized email addresses from Yahoo! Mail
> > http://personal.mail.yahoo.com/
> 


__
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/



Re: Configuration for Action

2001-06-21 Thread Mike Thompson

If your running in a J2EE container, you could always shove the entries into
the environment.  Then you could look them up like:

try
{
InitialContext ic = new InitialContext();
Object myparm = ic.lookup("the/jndi/name/of/your/parameter");
}
catch (javax.naming.NamingException ex)
{
//uh oh, error
}

- Original Message -
From: "Yuriy Zubarev" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, June 21, 2001 2:09 PM
Subject: Configuration for Action


> Hello everybody,
>
> While working directly with servlets, in configuration
> file you can specify initial valus of parameters for a servlet
> in the following way:
>
> 
>   
> parameter
>   
>   
> value
>   
> 
>
> And you can easily get those values without resorting to
> parse information on your own.
>
> So I was wondering if it's possible to make such a
> thing with actions in struts-config.xml file.
> In another words I would like to have some custom
> parameters for some actions with handy means of
> extracting those parameters.
>
> Thank you for your time.
>
> Best of luck,
> Yuriy Zubarev
>
>
> __
> Do You Yahoo!?
> Get personalized email addresses from Yahoo! Mail
> http://personal.mail.yahoo.com/