You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Scott A. Roehrig" <sa...@hotmail.com> on 2002/02/06 18:45:43 UTC
dynamically creating and registering an action with controller
I have a need to do the following...
I have an xml configuration file that will contain actions that will be
called by struts.
I want to be able to parse the file and add the mappings to the controller
during setup. I do not want the action mappings placed in the
struts-config.xml file. In addition, I also need to add an initialized
action to the controller so that it does not attempt to create the instance,
rather it uses the one I have created and registered.
It looks like this should be possible. So far I have something like the
following...
private void addMappings(Parser parser) {
// retrieve benches-Each bench is a class that extends the Action class
java.util.List benches = parser.getBenches();
java.util.ListIterator iterator = benches.listIterator();
while (iterator.hasNext()) {
org.apache.struts.action.ActionMapping mapping = new
org.apache.struts.action.ActionMapping();
BenchImpl benchImpl = (BenchImpl)iterator.next();
mapping.setPath(benchImpl.getBenchUri());
mapping.setType(benchImpl.getClass().toString());
servlet.addMapping(mapping);
// Workbench is a servlet that extends ActionServlet
((org.apache.cafe.workbench.Workbench)servlet).addAction(benchImpl.getBenchN
ame(), benchImpl);
}
}
The addAction method is as follows
/**
*
* Adds action to map
* @param String
* @param org.apache.struts.action.Action
*
*/
protected void addAction(String actionName, Action action) {
actions.put(actionName, action);
}
Seems like it should work, but the controller is still trying to initialize
a new instance of the bench when the mapping is called.
Any suggestions or clarifications?
Thanks!
Scott A. Roehrig
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: dynamically creating and registering an action with controller
Posted by "Scott A. Roehrig" <sa...@hotmail.com>.
Alright,
it is working. However, the put in the org.apache.struts.util.FastHashMap is
deprecated. It indicates that the commons fasthashmap will be used? Is this
change in the works?
Thanks as always:)
Scott
----- Original Message -----
From: "Scott A. Roehrig" <sa...@hotmail.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, February 06, 2002 12:45 PM
Subject: dynamically creating and registering an action with controller
> I have a need to do the following...
>
> I have an xml configuration file that will contain actions that will be
> called by struts.
>
> I want to be able to parse the file and add the mappings to the controller
> during setup. I do not want the action mappings placed in the
> struts-config.xml file. In addition, I also need to add an initialized
> action to the controller so that it does not attempt to create the
instance,
> rather it uses the one I have created and registered.
>
> It looks like this should be possible. So far I have something like the
> following...
>
> private void addMappings(Parser parser) {
> // retrieve benches-Each bench is a class that extends the Action
class
> java.util.List benches = parser.getBenches();
> java.util.ListIterator iterator = benches.listIterator();
> while (iterator.hasNext()) {
> org.apache.struts.action.ActionMapping mapping = new
> org.apache.struts.action.ActionMapping();
> BenchImpl benchImpl = (BenchImpl)iterator.next();
> mapping.setPath(benchImpl.getBenchUri());
> mapping.setType(benchImpl.getClass().toString());
> servlet.addMapping(mapping);
> // Workbench is a servlet that extends ActionServlet
>
>
((org.apache.cafe.workbench.Workbench)servlet).addAction(benchImpl.getBenchN
> ame(), benchImpl);
> }
> }
>
> The addAction method is as follows
>
> /**
> *
> * Adds action to map
> * @param String
> * @param org.apache.struts.action.Action
> *
> */
> protected void addAction(String actionName, Action action) {
> actions.put(actionName, action);
> }
>
> Seems like it should work, but the controller is still trying to
initialize
> a new instance of the bench when the mapping is called.
>
> Any suggestions or clarifications?
>
> Thanks!
> Scott A. Roehrig
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>