/**
     * Set a override map containing <code>key -> values</code> that takes 
precedent when doing find operations on the ValueStack.
     * <p/>
     * See the unit test for ValueStackTest for examples.
     * @param overrides  overrides map.
     */
//best not to use Map <String,Object> when you want to push a browser object 
into the map
//use Map<Object,Object> instead as seen here
    Map<Object, Object> overrides=new HashMap<Object, Object>();

//push any object you want into the overrides map
    overrides.put("browser", userSession.getBrowser());
            
ActionContext.getContext().getValueStack().setExprOverrides(overrides);

//now when you use ValueStack.findValue(String expr) you will find the object 
(including browser) from the overrides map

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger 
sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung 
oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. 
Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung 
fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le 
destinataire prévu, nous te demandons avec bonté que pour satisfaire informez 
l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est 
interdite. Ce message sert à l'information seulement et n'aura pas n'importe 
quel effet légalement obligatoire. Étant donné que les email peuvent facilement 
être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité 
pour le contenu fourni.




> Date: Fri, 4 Feb 2011 18:27:53 +0900
> From: li.wei.linf...@gmail.com
> To: user@struts.apache.org
> CC: rubens.go...@appia.com
> Subject: Re: S2 Action Setter Not Called
> 
> the problem is that you pushed a HashMap on the ValueStack's root.
> 
> if you do that, all the values will be populated to the HashMap, not 
> your action class
> 
> you can try this code to fix it.
> 
>   ActionContext.getContext().put("browser", userSession.getBrowser());
> 
> 
> 
> (2011/02/04 17:12), Rubens Gomes wrote:
> > Okay.  I found what is causing the setters not to be called.   I have an 
> > interceptor called ValueStackInterceptor (which is called prior to 
> > ParametersInterceptors) that is placing a String variable "browser" on the 
> > stack (please, see code below). If I comment out the line that places this 
> > variable on the stack (see below) everything works fine.  I am showing the 
> > Interceptor and the line of code that is causing a problem.
> >
> > Can someone please help me understand what is the problem with this code?
> >
> >
> > -----------------------------------------
> >
> > package com.softlagos.web.struts2.interceptor;
> >
> > import java.util.HashMap;
> > import java.util.Map;
> >
> > import javax.servlet.http.HttpServletRequest;
> >
> > import org.apache.commons.lang.xwork.StringUtils;
> > import org.apache.commons.logging.Log;
> > import org.apache.commons.logging.LogFactory;
> > import org.apache.struts2.ServletActionContext;
> >
> > import com.opensymphony.xwork2.ActionContext;
> > import com.opensymphony.xwork2.ActionInvocation;
> > import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
> > import com.softlagos.web.common.UserSession;
> > import com.softlagos.web.common.WebAppUtils;
> >
> >
> > /**
> >   * Interceptor object used to initialize the Struts 2 Value Stack with 
> > some state information (like the
> >   * browser variable) that is needed in the results.
> >   *
> >   * @author  Rubens Gomes
> >   * @version $Id: ValueStackInterceptor.java 3754 2011-02-03 00:39:46Z 
> > rgomes $
> >   */
> > public final class ValueStackInterceptor extends AbstractInterceptor
> > {
> >      private static final long serialVersionUID = 1;
> >      private static final Log logger = 
> > LogFactory.getLog(ValueStackInterceptor.class.getName());
> >
> >      public ValueStackInterceptor()
> >      {
> >          super();
> >      }
> >
> >      @Override
> >      public String intercept(final ActionInvocation invocation)
> >          throws Exception
> >      {
> >          HttpServletRequest request = ServletActionContext.getRequest();
> >          UserSession userSession = WebAppUtils.getUserSession(request);
> >
> >          /*
> >           * The DetectUserAgentFilter code should be run prior to Struts 2 
> > filter because that filter
> >           * is responsible for setting the browser on the HTTP userSession 
> > session object.
> >           */
> >          if(userSession==null)
> >              throw new IllegalStateException("The userSession was not 
> > set.");
> >
> >          if(StringUtils.isBlank(userSession.getBrowser()))
> >          {
> >              String msg = "The userSession browser is null, which means 
> > that the user agent detection failed.  Code cannot proceed at this point.";
> >              IllegalStateException ex = new IllegalStateException(msg);
> >              logger.error(msg, ex);
> >              throw ex;
> >          }
> >          if(logger.isInfoEnabled())
> >              logger.info("Setting Struts2 value stack browser [" + 
> > userSession.getBrowser() + "].");
> >
> >          Map<String, Object>  context = new HashMap<String, Object>();
> >          // browser is used on Result objects to render either a desktop or 
> > mobile JSP page.
> >
> >          context.put("browser", userSession.getBrowser());
> >
> > /*  ---->>>   THE FOLLOWING LINE IS IMPACTING ON ACTION SETTER NOT TO BE 
> > CALLED<<<  ---- */
> >          ActionContext.getContext().getValueStack().push(context);
> >
> >
> >          /* --- Reverse Path --- */
> >          return invocation.invoke();
> >      }
> > }
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> > For additional commands, e-mail: user-h...@struts.apache.org
> >
> 
                                          

Reply via email to