RE: Accessing application scope in Action.execute()

2003-11-12 Thread Geert Van Landeghem
The Action class contains the protected ActionServlet servlet variable
through which each subclass can access the servlet context.

A good approach to accessing session and application objects is by 
extending the Action class (I've got this from O'Reilly's Programming
Jakarta Struts)

By extending this class all your action classes inherit these common
methods (getSessionObject, getApplicationObject, ...)

abstract public class EnterpriseBaseAction extends Action {
  /**
   * Retrieve a session object based on the request and the attribute name.
   */
  protected Object getSessionObject(HttpServletRequest req,
String attrName) {
Object sessionObj = null;
HttpSession session = req.getSession(false);
if ( session != null ){
   sessionObj = session.getAttribute(attrName);
}
return sessionObj;
  }

  /**
   * Retrieve an object from the application scope by its name. This is
   * a convience method.
   */
  protected Object getApplicationObject(String attrName) {
return servlet.getServletContext().getAttribute(attrName);
  }

  public boolean isLoggedIn( HttpServletRequest request ){
UserContainer container = getUserContainer(request);
if ( container.getUserView() != null ){
   return true;
}else{
  return false;
}
  }

  /**
   * Return the instance of the ApplicationContainer object.
   */
  protected ApplicationContainer getApplicationContainer() {
return 
(ApplicationContainer)getApplicationObject(IConstants.APPLICATION_CONTAINER_KEY);
  }

  /**
   * Retrieve the UserContainer for the user tier to the request.
   */
  protected UserContainer getUserContainer(HttpServletRequest request) {

UserContainer userContainer = (UserContainer)getSessionObject(request, 
IConstants.USER_CONTAINER_KEY);

// Create a UserContainer for the user if it doesn't exist already
if(userContainer == null) {
  userContainer = new UserContainer();
  userContainer.setLocale(request.getLocale());
  HttpSession session = request.getSession(true);
  session.setAttribute(IConstants.USER_CONTAINER_KEY, userContainer);
}

return userContainer;
  }
}


-Original Message-
From: Looser [mailto:[EMAIL PROTECTED]
Sent: maandag 10 november 2003 16:03
To: struts Mailinglist
Subject: Accessing application scope in Action.execute()


Hi,

is there any chance to access objects in application scope in my action 
classes ?

I have to override the .execute(ActionMapping mapping,ActionForm 
form,HttpServletRequest request,HttpServletResponse response) method but 
none of these parameters give me access to application scope like 
'getServletContext().getAttribute("myAttribute")' would do.

Which is the best practise to store objects in application scope and 
retrieve them back in my ActionClasses ?

Thx for your answers...


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


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



Re: Accessing application scope in Action.execute()

2003-11-10 Thread Frank Schaare
Hi David,

getServlet() followed by two more commands:

getServlet().getServletContext().getAttribute(String);
OR
getServlet().getServletContext().setAttribute(String, obj);
Regards,

this was a great help for me thank you.

Hope my name is shown correctly now...

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


RE: Accessing application scope in Action.execute()

2003-11-10 Thread David Friedman
Dear Looser, 

Inside the execute, you can set/get application
scope properties using the Action class methods
getServlet() followed by two more commands:

getServlet().getServletContext().getAttribute(String);
OR
getServlet().getServletContext().setAttribute(String, obj);

Regards,
David

-Original Message-
From: Looser [mailto:[EMAIL PROTECTED]
Sent: Monday, November 10, 2003 10:03 AM
To: struts Mailinglist
Subject: Accessing application scope in Action.execute()


Hi,

is there any chance to access objects in application scope in my action 
classes ?

I have to override the .execute(ActionMapping mapping,ActionForm 
form,HttpServletRequest request,HttpServletResponse response) method but 
none of these parameters give me access to application scope like 
'getServletContext().getAttribute("myAttribute")' would do.

Which is the best practise to store objects in application scope and 
retrieve them back in my ActionClasses ?

Thx for your answers...


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


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



Accessing application scope in Action.execute()

2003-11-10 Thread Looser
Hi,

is there any chance to access objects in application scope in my action 
classes ?

I have to override the .execute(ActionMapping mapping,ActionForm 
form,HttpServletRequest request,HttpServletResponse response) method but 
none of these parameters give me access to application scope like 
'getServletContext().getAttribute("myAttribute")' would do.

Which is the best practise to store objects in application scope and 
retrieve them back in my ActionClasses ?

Thx for your answers...

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