[ http://issues.apache.org/struts/browse/WW-1415?page=all ]

Christopher Waring updated WW-1415:
-----------------------------------

    Attachment: StrutsVariableResolver_diff.txt

> Updated the StrutsVariableResolver to add OGNL support for resolving variable 
> names
> -----------------------------------------------------------------------------------
>
>                 Key: WW-1415
>                 URL: http://issues.apache.org/struts/browse/WW-1415
>             Project: Struts 2
>          Issue Type: New Feature
>          Components: Expression Language, Misc
>    Affects Versions: 2.0.0, 2.0.1
>         Environment: All
>            Reporter: Christopher Waring
>         Assigned To: Don Brown
>         Attachments: StrutsVariableResolver_diff.txt
>
>
> Changed StrutsVariableResolver to first return the current Action if the 
> Action name matches the requested variable name.  Otherwise try the value 
> stack to resolve the variable.  Otherwise delegate to the original jsf 
> variable resolver.
> This allows you to use things like the following with your JSF EL expressions:
> <h:outputText value="#{billingAction.billingActions[editId].baId}" />
> (Where "billingAction" is the name of your action, "billingActions" is a List 
> property of the action, "editId" is a Long property of the action, "baId" is 
> a property of a model object with in the List.)
> This will also work:
> <h:outputText value="#{billingActions[editId].baId}" />
> (Same as above but starting with a property of the action rather than the 
> action itself.)
> org.apache.struts2.jsf.StrutsVariableResolver.java
> /*
>  * $Id: TokenInterceptor.java 394468 2006-04-16 12:16:03Z tmjee $
>  *
>  * Copyright 2006 The Apache Software Foundation.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>  * You may obtain a copy of the License at
>  *
>  *      http://www.apache.org/licenses/LICENSE-2.0
>  *
>  * Unless required by applicable law or agreed to in writing, software
>  * distributed under the License is distributed on an "AS IS" BASIS,
>  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>  * See the License for the specific language governing permissions and
>  * limitations under the License.
>  */
> package org.apache.struts2.jsf;
> import javax.faces.context.FacesContext;
> import javax.faces.el.EvaluationException;
> import javax.faces.el.VariableResolver;
> import com.opensymphony.xwork2.ActionContext;
> import com.opensymphony.xwork2.util.OgnlValueStack;
> /**
>  * Will return a reference to the current action if the action name matches
>  * the requested variable name.  Otherwise it will attempt to resolve the 
>  * name from the value stack. Otherwise it will delegate to the original jsf
>  * resolver.
>  */
> public class StrutsVariableResolver extends VariableResolver {
>       /** The original <code>VariableResolver</code> passed to our 
> constructor. */
>       private VariableResolver original = null;
>       /** The variable name of our Struts action */
>       private static final String STRUTS_VARIABLE_NAME = "action";
>       /**
>        * Constructor
>        * 
>        * @param original
>        *            Original resolver to delegate to.
>        */
>       public StrutsVariableResolver(VariableResolver original) {
>               this.original = original;
>       }
>       /**
>        * <p>
>        * Will return a reference to the current action if the action name 
> matches
>        * the requested variable name.  Otherwise it will attempt to resolve 
> the 
>        * name from the value stack. Otherwise it will delegate to the 
> original jsf
>        * resolver.
>        * </p>
>        * 
>        * @param name
>        *            Variable name to be resolved
>        */
>       public Object resolveVariable(FacesContext context, String name)
>                       throws EvaluationException {
>               
>               String actionName = ActionContext.getContext().getName();
>               
>               if(actionName.equals(name)) {
>                       return 
> ActionContext.getContext().getActionInvocation().getAction();
>               }
>               
>               Object obj = 
> ActionContext.getContext().getValueStack().findValue(name);
>               if (obj != null) {
>                       return obj;
>               } else {
>                       return original.resolveVariable(context, name);
>               }
>       }
> }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/struts/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to