On 10/6/05, Koen Jans <[EMAIL PROTECTED]> wrote:
>
> >What BaseActions also can do is to instantiate and manage resources
> >(yes servlet content listener can do this too, but i like to have it
> >in one place), services and so on. They also provide methods to handle
> >request parameters typed (getStringParameter, getIntParameter) for
> >pages which don't use forms.
>
> I am not sure how you can manage a resource in the BaseAction, let's
> take for instance a Database or a Logger object. The users guide on the
> struts website states that we can only use local variables in an Action
> class to be thread safe in a multi-threaded environment.

Well you shouldn't have anything with Database in the name in your
action, it should be encapsulated in a service POJO.

As for the logger, I do in BaseAction:
        protected Logger log;

        protected BaseAction() {
                log = Logger.getLogger(this.getClass());
                
                ActionRegistry.getInstance().registerAction(this);
                stats = new ActionStats();
        }

This way you have a logger instance accessible for all subactions
atuomatically, with full class name support (I use log4j) for
different log-files filtering. As for the second part, I have a
"Registry" where each Action is registered, and the BaseAction counts
requests, errors, mid/min/max execution times and sucess rates for
every subaction. I have an administration interface (actions)
somewhere else, where I can see this data for every action which has
been used more than once.

regards
Leon

P.S. The last functionality is available in a separate struts-add-on
lib, which I can provide you if you are interested.

P.P.S. Naturally this all works only if you don't instantiate actions
directly, but let the framework to instantiate one-instance-per-class

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to