You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Peter Maas <pe...@noterik.nl> on 2004/12/20 22:55:03 UTC
Custom action mapping / or configuration of actions....
If I want to configure parameters for a certain action in a
non-hardcoded fashion; what would be the way to go?
I see:
- people using the application.properties resources file... seems not
o.k. to me... this is where I store texts for the interface
- people using attributes stored in servlet context
- people using properties set using the <set-property> element retrieved
by custom action mappings
- people using properties set using the <set-property> element retrieved
by custom action mappings (???? I can not find a good example for this)
To me the <set-property> seems te most logical to use (since it also
feature xdoclet support).
But from there, where do I go? How do I access the variable?
I have seen the example using a custom ActionMapping, but I found it a
bit strange that I can only define this in the <action-mappings>
element... i.e. globally over all my actions?
Then there is ActionConfig... which sounds like what I need... but how
do I use it to retrieve properties? anyone got an example?
thanks in advance!
--
Peter Maas
Application Architect / Streaming
Noterik Multimedia BV
Prins Hendrikkade 120
1011 AM Amsterdam
The Netherlands
Tel: +31 (0)205929966
Fax: +31 (0)204688405
Gsm: +31 (0)624687952
Web: www.noterik.nl
--------------------------------------
Take a look at our streaming solutions:
http://www.streamedit.com/demo.html
Get firefox:
http://www.mozilla.org/products/firefox/
---------------------------------------
:wq!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Custom action mapping / or configuration of actions....
Posted by Peter Maas <pe...@noterik.nl>.
Thank you for your response!
to bad xdoclet doesn't allow the className option...
the controller setup for actionmapping works though...
On Mon, 2004-12-20 at 17:00 -0600, Joe Germuska wrote:
> >When I do this I get a runtime error (I can understand that the
> >actionmapping does not have this property...):
>
> Ah... so you have to tell Struts to use your custom subclass. This
> can be done for a single element using
>
> <action className="com.example.MyActionMapping" ...>
>
> or if you want to use it for all action mappings,
>
> <action-mappings type="com.example.MyActionMapping">
> ...
>
> Note that I think there's a problem where if you use a custom
> action-mapping in the <action-mappings> element and you use a list of
> struts-config files, the value has a wider use than you'd expect -- I
> believe someone on my team told me that it also applied to action
> mappings in other struts config files which were processed later.
> You'd expect it would only apply to the action elements which are a
> child of the action-mappings element where that value is declared.
> I'll ask him to confirm and file a bug if that's true...
>
> Joe
>
>
>
>
> >//----------- stacktrace---------
> >
> >Dec 20, 2004 11:34:30 PM org.apache.commons.digester.Digester
> >startElement
> >SEVERE: Begin event threw exception
> >java.lang.NoSuchMethodException: Bean has no property named cacheTimeout
> > at
> >org.apache.commons.digester.SetPropertyRule.begin(SetPropertyRule.java:192)
> > at org.apache.commons.digester.Rule.begin(Rule.java:200)
> > at
> >org.apache.commons.digester.Digester.startElement(Digester.java:1273)
> > at
> >com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:485)
> > at
> >com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentPars
> >
> >----------- stacktrace---------//
> >
> >Do I have to specify a custom actionmapping to get this done? Can this
> >be specified per action or do I have to specify it globally in the
> ><action-mappings> parent...?
> >
>
--
Peter Maas
Application Architect / Streaming
Noterik Multimedia BV
Prins Hendrikkade 120
1011 AM Amsterdam
The Netherlands
Tel: +31 (0)205929966
Fax: +31 (0)204688405
Gsm: +31 (0)624687952
Web: www.noterik.nl
--------------------------------------
Take a look at our streaming solutions:
http://www.streamedit.com/demo.html
Get firefox:
http://www.mozilla.org/products/firefox/
---------------------------------------
:wq!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Custom action mapping / or configuration of actions....
Posted by Joe Germuska <Jo...@Germuska.com>.
>When I do this I get a runtime error (I can understand that the
>actionmapping does not have this property...):
Ah... so you have to tell Struts to use your custom subclass. This
can be done for a single element using
<action className="com.example.MyActionMapping" ...>
or if you want to use it for all action mappings,
<action-mappings type="com.example.MyActionMapping">
...
Note that I think there's a problem where if you use a custom
action-mapping in the <action-mappings> element and you use a list of
struts-config files, the value has a wider use than you'd expect -- I
believe someone on my team told me that it also applied to action
mappings in other struts config files which were processed later.
You'd expect it would only apply to the action elements which are a
child of the action-mappings element where that value is declared.
I'll ask him to confirm and file a bug if that's true...
Joe
>//----------- stacktrace---------
>
>Dec 20, 2004 11:34:30 PM org.apache.commons.digester.Digester
>startElement
>SEVERE: Begin event threw exception
>java.lang.NoSuchMethodException: Bean has no property named cacheTimeout
> at
>org.apache.commons.digester.SetPropertyRule.begin(SetPropertyRule.java:192)
> at org.apache.commons.digester.Rule.begin(Rule.java:200)
> at
>org.apache.commons.digester.Digester.startElement(Digester.java:1273)
> at
>com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:485)
> at
>com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentPars
>
>----------- stacktrace---------//
>
>Do I have to specify a custom actionmapping to get this done? Can this
>be specified per action or do I have to specify it globally in the
><action-mappings> parent...?
>
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction" -The Ex
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Custom action mapping / or configuration of actions....
Posted by Peter Maas <pe...@noterik.nl>.
On Mon, 2004-12-20 at 16:22 -0600, Joe Germuska wrote:
> At 10:55 PM +0100 12/20/04, Peter Maas wrote:
> >If I want to configure parameters for a certain action in a
> >non-hardcoded fashion; what would be the way to go?
> >
> >I see:
> >- people using the application.properties resources file... seems not
> >o.k. to me... this is where I store texts for the interface
> >- people using attributes stored in servlet context
> >- people using properties set using the <set-property> element retrieved
> >by custom action mappings
> >- people using properties set using the <set-property> element retrieved
> >by custom action mappings (???? I can not find a good example for this)
> >
> >To me the <set-property> seems te most logical to use (since it also
> >feature xdoclet support).
> >
> >But from there, where do I go? How do I access the variable?
> >I have seen the example using a custom ActionMapping, but I found it a
> >bit strange that I can only define this in the <action-mappings>
> >element... i.e. globally over all my actions?
> >
> >Then there is ActionConfig... which sounds like what I need... but how
> >do I use it to retrieve properties? anyone got an example?
>
> ActionMapping extends ActionConfig. Conventionally, Action classes
> cast ActionMapping to a specific subclass which is known to have the
> properties they expect to be passed in.
>
> Something like this:
>
> public ActionForward execute(...) {
>
> String config = ((MyActionMapping) mapping).getConfigProperty();
> }
>
> and
>
> <set-property property="configProperty" value="foobar" />
>
> Note that if you only need one value, the "parameter" property of
> ActionMapping is the easiest way to go. Also, just last week, I
> committed changes that allow you to access a map of arbitrary
> properties in an ActionConfig, if you're willing to use a nightly
> build of Struts. This should eliminate most cases for actually
> subclassing ActionMapping.
>
When I do this I get a runtime error (I can understand that the
actionmapping does not have this property...):
//----------- stacktrace---------
Dec 20, 2004 11:34:30 PM org.apache.commons.digester.Digester
startElement
SEVERE: Begin event threw exception
java.lang.NoSuchMethodException: Bean has no property named cacheTimeout
at
org.apache.commons.digester.SetPropertyRule.begin(SetPropertyRule.java:192)
at org.apache.commons.digester.Rule.begin(Rule.java:200)
at
org.apache.commons.digester.Digester.startElement(Digester.java:1273)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:485)
at
com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentPars
----------- stacktrace---------//
Do I have to specify a custom actionmapping to get this done? Can this
be specified per action or do I have to specify it globally in the
<action-mappings> parent...?
> Joe
>
>
--
Peter Maas
Application Architect / Streaming
Noterik Multimedia BV
Prins Hendrikkade 120
1011 AM Amsterdam
The Netherlands
Tel: +31 (0)205929966
Fax: +31 (0)204688405
Gsm: +31 (0)624687952
Web: www.noterik.nl
--------------------------------------
Take a look at our streaming solutions:
http://www.streamedit.com/demo.html
Get firefox:
http://www.mozilla.org/products/firefox/
---------------------------------------
:wq!
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Custom action mapping / or configuration of actions....
Posted by Joe Germuska <Jo...@Germuska.com>.
At 10:55 PM +0100 12/20/04, Peter Maas wrote:
>If I want to configure parameters for a certain action in a
>non-hardcoded fashion; what would be the way to go?
>
>I see:
>- people using the application.properties resources file... seems not
>o.k. to me... this is where I store texts for the interface
>- people using attributes stored in servlet context
>- people using properties set using the <set-property> element retrieved
>by custom action mappings
>- people using properties set using the <set-property> element retrieved
>by custom action mappings (???? I can not find a good example for this)
>
>To me the <set-property> seems te most logical to use (since it also
>feature xdoclet support).
>
>But from there, where do I go? How do I access the variable?
>I have seen the example using a custom ActionMapping, but I found it a
>bit strange that I can only define this in the <action-mappings>
>element... i.e. globally over all my actions?
>
>Then there is ActionConfig... which sounds like what I need... but how
>do I use it to retrieve properties? anyone got an example?
ActionMapping extends ActionConfig. Conventionally, Action classes
cast ActionMapping to a specific subclass which is known to have the
properties they expect to be passed in.
Something like this:
public ActionForward execute(...) {
String config = ((MyActionMapping) mapping).getConfigProperty();
}
and
<set-property property="configProperty" value="foobar" />
Note that if you only need one value, the "parameter" property of
ActionMapping is the easiest way to go. Also, just last week, I
committed changes that allow you to access a map of arbitrary
properties in an ActionConfig, if you're willing to use a nightly
build of Struts. This should eliminate most cases for actually
subclassing ActionMapping.
Joe
--
Joe Germuska
Joe@Germuska.com
http://blog.germuska.com
"Narrow minds are weapons made for mass destruction" -The Ex
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org