You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Yuriy Zubarev <yu...@yahoo.ca> on 2001/06/21 21:09:10 UTC

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:

<init-param>
  <param-name>
    parameter
  </param-name>
  <param-value>
    value
  </param-value>
</init-param>

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

Posted by Yuriy Zubarev <yu...@yahoo.ca>.
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 <mr...@instanton.com> 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" <yu...@yahoo.ca>
> To: <st...@jakarta.apache.org>
> 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:
> >
> > <init-param>
> >   <param-name>
> >     parameter
> >   </param-name>
> >   <param-value>
> >     value
> >   </param-value>
> > </init-param>
> >
> > 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

Posted by Mike Thompson <mr...@instanton.com>.
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" <yu...@yahoo.ca>
To: <st...@jakarta.apache.org>
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:
>
> <init-param>
>   <param-name>
>     parameter
>   </param-name>
>   <param-value>
>     value
>   </param-value>
> </init-param>
>
> 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/


Problem solved - Re: newbie - requesting example of working build.xml, build.propertiesfiles

Posted by Michael McCafferty <mi...@organic.com>.

"Craig R. McClanahan" wrote:
> 

[ snipped ]

> You should not have to modify *anything* in build.xml, build-webapp.xml,
> or build-webapps.xml in order to build Struts from source.  All of the
> necessary values are inherited from properties you set inside your
> build.properties file.
> 

Many thanks for the prompt responses from this list. I'm impressed. 

I don't know if I accidentally deleted the file yesterday (more likely,
also more embarrasing, than an unreported error while checking the files
out from CVS), but the set of files I was working with did not contain a
"build.xml" file, which was the ultimate source of my confusion and
failure.

I had checked out the files via anonymous CVS and was using the
resulting directory as a clean template. I'd copy the tamplate to a work
space, try a build, analyze the problem, blow away and recopy the
template, and repeat. But since the template did not contain a copy of
build.xml, I was under the impression that I needed to create/modify my
own, and spent a great deal of time on that. Learned a lot about "ant,"
though, so I guess it was a Learning Experience ;-)

Thanks again for the assistance,

-- 
Michael McCafferty 
Senior Server Engineer
Enterprise Applications, Organic
415-581-5785 mikemcc@organic.com

Re: newbie - requesting example of working build.xml, build.properties files

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 22 Jun 2001, Michael McCafferty wrote:

> Hi all,
> 
> I am trying to build struts from source, and having an unexpectedly
> difficult time of it. I have downloaded the source code from CVS, and
> followed the directions listed on
> http://jakarta.apache.org/struts/installation.html without success.
> 
> I have copied the $STRUTS/build.properties.sample to build.properties
> and edited existing entries accordingly. I have also copied
> $STRUTS/build-webapp.xml to build.xml and edited existing values
> accordingly.  For all prerequesite properties listed in build-webapp.xml
> (lines 29-86) I am specifying a command line option to "ant." 
> 
> I'm probably missing something obvious, but I'm coming to the conclusion
> that the sample configuration files require a LOT of customization in
> order to build a vanilla version of struts from source. I'd love to see
> copies of build.xml and build.properties that someone has used to
> successfully compile the software.
> 

You should not have to modify *anything* in build.xml, build-webapp.xml,
or build-webapps.xml in order to build Struts from source.  All of the
necessary values are inherited from properties you set inside your
build.properties file.

The minimal set of properties you need to set in your
"build.properties" file are:

  jdbc20ext.jar - Set this to the full pathname to your
                  "jdbc2_0-stdext.jar" file (download the
                  JDBC 2.0 Optional Package).

  servlet.jar   - Set this to the full pathname to your
                  "servlet.jar" file (normally the one you
                  got with your servlet container).

For the rest of my setup, here's what I did:

* Downloaded Ant 1.3 and installed it (and placed $ANT_HOME/bin
  on my PATH)

* From the same place, grab Ant's "optional.jar" file and
  place it in $ANT_HOME/lib.

* Download JAXP/1.1 and put all three JAR files on my CLASSPATH.

* Type "ant" to compile Struts, or "ant dist" to create a mirror
  of the binary distribution.

If you are having to change other properties, then we should try to
simplify the build scripts so that you don't have to.

> Thanks in advance,
> 
> Michael McCafferty
> mikemcc@organic.com
> 

Craig McClanahan



newbie - requesting example of working build.xml, build.properties files

Posted by Michael McCafferty <mi...@organic.com>.
Hi all,

I am trying to build struts from source, and having an unexpectedly
difficult time of it. I have downloaded the source code from CVS, and
followed the directions listed on
http://jakarta.apache.org/struts/installation.html without success.

I have copied the $STRUTS/build.properties.sample to build.properties
and edited existing entries accordingly. I have also copied
$STRUTS/build-webapp.xml to build.xml and edited existing values
accordingly.  For all prerequesite properties listed in build-webapp.xml
(lines 29-86) I am specifying a command line option to "ant." 

I'm probably missing something obvious, but I'm coming to the conclusion
that the sample configuration files require a LOT of customization in
order to build a vanilla version of struts from source. I'd love to see
copies of build.xml and build.properties that someone has used to
successfully compile the software.

Thanks in advance,

Michael McCafferty
mikemcc@organic.com

Re: Configuration for Action

Posted by "Craig R. McClanahan" <cr...@apache.org>.

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" <cr...@apache.org> 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 <action> entries in two respects:
> >   - Tell Struts to use your ActionMapping subclass instead of the
> >     standard one.
> >   - Configure the extra parameters with <set-property> elements>
> > 
> >     <action path="/myaction"
> >        className="com.mycompany.MyActionMapping"
> >             type="com.mycompany.MyAction"
> >             ... >
> >       <set-property property="foo" value="Value for property foo"/>
> >       <set-property property="bar" value="Value for property bar"/>
> >     </action>
> > 
> > * 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:
> > > 
> > > <init-param>
> > >   <param-name>
> > >     parameter
> > >   </param-name>
> > >   <param-value>
> > >     value
> > >   </param-value>
> > > </init-param>
> > > 
> > > 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

Posted by Yuriy Zubarev <yu...@yahoo.ca>.
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" <cr...@apache.org> 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 <action> entries in two respects:
>   - Tell Struts to use your ActionMapping subclass instead of the
>     standard one.
>   - Configure the extra parameters with <set-property> elements>
> 
>     <action path="/myaction"
>        className="com.mycompany.MyActionMapping"
>             type="com.mycompany.MyAction"
>             ... >
>       <set-property property="foo" value="Value for property foo"/>
>       <set-property property="bar" value="Value for property bar"/>
>     </action>
> 
> * 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:
> > 
> > <init-param>
> >   <param-name>
> >     parameter
> >   </param-name>
> >   <param-value>
> >     value
> >   </param-value>
> > </init-param>
> > 
> > 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

Posted by "Craig R. McClanahan" <cr...@apache.org>.
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 <action> entries in two respects:
  - Tell Struts to use your ActionMapping subclass instead of the
    standard one.
  - Configure the extra parameters with <set-property> elements>

    <action path="/myaction"
       className="com.mycompany.MyActionMapping"
            type="com.mycompany.MyAction"
            ... >
      <set-property property="foo" value="Value for property foo"/>
      <set-property property="bar" value="Value for property bar"/>
    </action>

* 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:
> 
> <init-param>
>   <param-name>
>     parameter
>   </param-name>
>   <param-value>
>     value
>   </param-value>
> </init-param>
> 
> 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/
>