You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by EL AKARI Mehdi <me...@hotmail.com> on 2003/12/19 11:51:52 UTC

How to put an object into the application scope from a plugin interface

Hi,
I'm writing a struts plugin, and i need to put an object into the application scope.
How can i do this.
Note that the plugin interface contains the following methods:
    public void init(ActionServlet servlet, ModuleConfig config) throws javax.servlet.ServletException  ;
    public void destroy() ;


thanks 
Mehdi

Re: How to put an object into the application scope from a plugin interface

Posted by EL AKARI Mehdi <me...@hotmail.com>.
I'm using struts 1.1 and in java doc it is said that ApplicationConfig is
deprecated and we must use now ModuleConfig.
If you take a look on the tiles pluggin you will find that it implements
this interface.
my question is how to put in the "ModuleScope" an object, and how to
retrieve it again?
Mehdi



----- Original Message ----- 
From: "Gurpreet Dhanoa" <gu...@smartdatainc.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, December 19, 2003 11:47 AM
Subject: Re: How to put an object into the application scope from a plugin
interface


> Mehdi
>
> i am talking about the same interface which is working onto my end
> which versio you are using
>
> ----- Original Message -----
> From: "EL AKARI Mehdi" <me...@hotmail.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Friday, December 19, 2003 5:06 PM
> Subject: Re: How to put an object into the application scope from a plugin
> interface
>
>
> > Which interface are you talking about, i'am using
> > org.apache.struts.action.PlugIn
> >
> > isn't it the good one ? Actualy it is working for me !
> > Mehdi
> >
> >
> > ----- Original Message -----
> > From: "Gurpreet Dhanoa" <gu...@smartdatainc.com>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Friday, December 19, 2003 11:10 AM
> > Subject: Re: How to put an object into the application scope from a
plugin
> > interface
> >
> >
> > > hi THink you are slightly wrong
> > >
> > >
> > > syntax for init method is
> > >
> > >
> > > ublic void init(ActionServlet servlet,
> > >   ApplicationConfig applicationConfig)  throws
> > > javax.servlet.ServletException {
> > > }
> > >
> > >
> > > So you can access Application object and can set the attribute intop
it
> > >
> > >
> > > Regards
> > > Gary
> > > ----- Original Message -----
> > > From: "EL AKARI Mehdi" <me...@hotmail.com>
> > > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > > Sent: Friday, December 19, 2003 4:21 PM
> > > Subject: How to put an object into the application scope from a plugin
> > > interface
> > >
> > >
> > > Hi,
> > > I'm writing a struts plugin, and i need to put an object into the
> > > application scope.
> > > How can i do this.
> > > Note that the plugin interface contains the following methods:
> > >     public void init(ActionServlet servlet, ModuleConfig config)
throws
> > > javax.servlet.ServletException  ;
> > >     public void destroy() ;
> > >
> > >
> > > thanks
> > > Mehdi
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How to put an object into the application scope from a plugin interface

Posted by Gurpreet Dhanoa <gu...@smartdatainc.com>.
Mehdi

i am talking about the same interface which is working onto my end
which versio you are using

----- Original Message -----
From: "EL AKARI Mehdi" <me...@hotmail.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, December 19, 2003 5:06 PM
Subject: Re: How to put an object into the application scope from a plugin
interface


> Which interface are you talking about, i'am using
> org.apache.struts.action.PlugIn
>
> isn't it the good one ? Actualy it is working for me !
> Mehdi
>
>
> ----- Original Message -----
> From: "Gurpreet Dhanoa" <gu...@smartdatainc.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Friday, December 19, 2003 11:10 AM
> Subject: Re: How to put an object into the application scope from a plugin
> interface
>
>
> > hi THink you are slightly wrong
> >
> >
> > syntax for init method is
> >
> >
> > ublic void init(ActionServlet servlet,
> >   ApplicationConfig applicationConfig)  throws
> > javax.servlet.ServletException {
> > }
> >
> >
> > So you can access Application object and can set the attribute intop it
> >
> >
> > Regards
> > Gary
> > ----- Original Message -----
> > From: "EL AKARI Mehdi" <me...@hotmail.com>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Friday, December 19, 2003 4:21 PM
> > Subject: How to put an object into the application scope from a plugin
> > interface
> >
> >
> > Hi,
> > I'm writing a struts plugin, and i need to put an object into the
> > application scope.
> > How can i do this.
> > Note that the plugin interface contains the following methods:
> >     public void init(ActionServlet servlet, ModuleConfig config) throws
> > javax.servlet.ServletException  ;
> >     public void destroy() ;
> >
> >
> > thanks
> > Mehdi
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How to put an object into the application scope from a plugin interface

Posted by EL AKARI Mehdi <me...@hotmail.com>.
Which interface are you talking about, i'am using
org.apache.struts.action.PlugIn

isn't it the good one ? Actualy it is working for me !
Mehdi


----- Original Message ----- 
From: "Gurpreet Dhanoa" <gu...@smartdatainc.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, December 19, 2003 11:10 AM
Subject: Re: How to put an object into the application scope from a plugin
interface


> hi THink you are slightly wrong
>
>
> syntax for init method is
>
>
> ublic void init(ActionServlet servlet,
>   ApplicationConfig applicationConfig)  throws
> javax.servlet.ServletException {
> }
>
>
> So you can access Application object and can set the attribute intop it
>
>
> Regards
> Gary
> ----- Original Message -----
> From: "EL AKARI Mehdi" <me...@hotmail.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Friday, December 19, 2003 4:21 PM
> Subject: How to put an object into the application scope from a plugin
> interface
>
>
> Hi,
> I'm writing a struts plugin, and i need to put an object into the
> application scope.
> How can i do this.
> Note that the plugin interface contains the following methods:
>     public void init(ActionServlet servlet, ModuleConfig config) throws
> javax.servlet.ServletException  ;
>     public void destroy() ;
>
>
> thanks
> Mehdi
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How to put an object into the application scope from a plugin interface

Posted by Gurpreet Dhanoa <gu...@smartdatainc.com>.
hi THink you are slightly wrong


syntax for init method is


ublic void init(ActionServlet servlet,
  ApplicationConfig applicationConfig)  throws
javax.servlet.ServletException {
}


So you can access Application object and can set the attribute intop it


Regards
Gary
----- Original Message -----
From: "EL AKARI Mehdi" <me...@hotmail.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Friday, December 19, 2003 4:21 PM
Subject: How to put an object into the application scope from a plugin
interface


Hi,
I'm writing a struts plugin, and i need to put an object into the
application scope.
How can i do this.
Note that the plugin interface contains the following methods:
    public void init(ActionServlet servlet, ModuleConfig config) throws
javax.servlet.ServletException  ;
    public void destroy() ;


thanks
Mehdi


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: How to put an object into the application scope from a plugin interface

Posted by Nathan Rogers <nr...@library.wisc.edu>.
EL AKARI Mehdi wrote:
> Hi,
> I'm writing a struts plugin, and i need to put an object into the application scope.
> How can i do this.
> Note that the plugin interface contains the following methods:
>     public void init(ActionServlet servlet, ModuleConfig config) throws javax.servlet.ServletException  ;
>     public void destroy() ;
> 
> 
> thanks 
> Mehdi

The easiest way is to use the ActionServlet object to get the 
ServletContext and push everything in that.

The code to do it is pretty simple

context = servlet.getServletContext();
context.setAttribute(KEY, object);

Then, within a page when you need to get something out you just retrieve 
the ServletContext and get the attribute back out.  Example :

context = servlet.getServletContext();
Object retrievedObject = (Object)context.getAttribute(KEY);




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org