myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "l.penet@senat.fr" <l.pe...@senat.fr>
Subject Re: Unwrap CC ValueExpression?
Date Mon, 13 May 2013 14:45:42 GMT
On 13/05/2013 14:35, Thomas Andraschko wrote:
> Hi Christian,
>
> i don't understand your solution exactly.
> Whats the difference?
> It would still store the #{cc.attrs.xxx} expression and #{cc} cant be
> evaluated without #pushComponentToEL(cc).
> Also #createView should be avoided for such a request IMO because of
> performance.
I use the following dirty/kludgy code for such needs :

         public static String getMappedValueExpression(ValueExpression 
valueExpression) {
             ContextAwareTagValueExpression ctxAware = 
(ContextAwareTagValueExpression)valueExpression;
             if(ctxAware != null) {
                 return 
getMappedValueExpression((WrappedValueExpression)ctxAware.getWrapped());
             }
             return valueExpression.getExpressionString();
         }

         public static String 
getMappedValueExpression(WrappedValueExpression wrappedExpression) {
             String exprString = 
wrappedExpression.getExpressionString().replace("#{", "").replace("}", "");
             String ret = exprString;
             try {

                 Field valueExpression = 
WrappedValueExpression.class.getDeclaredField("valueExpression");
                 valueExpression.setAccessible(true);
                 ValueExpressionImpl vei = (ValueExpressionImpl) 
valueExpression.get(wrappedExpression);
                 Field varMapper = 
ValueExpressionImpl.class.getDeclaredField("varMapper");
                 varMapper.setAccessible(true);
                 VariableMapperImpl vmi = (VariableMapperImpl) 
varMapper.get(vei);
                 if(vmi != null) {
                     String[] components = exprString.split("\\.");
                     components[0] = 
vmi.resolveVariable(components[0]).getExpressionString().replace("#{", 
"").replace("}", "");
                     ret = "";
                     for(int i = 0 ; i < components.length ; i++) {
                         if(i != 0) {
                             ret += ".";
                         }
                         ret += components[i];
                     }
                 }
             } catch (Exception ex) {
                 logger.error("Exception lors du mapping de l'expression 
EL " + exprString, ex);
             } finally {
                 return ret;
             }
         }

I will gladly adopt a better solution but this one works for me. :-)

Regards,

Ludovic
|
| AVANT D'IMPRIMER, PENSEZ A L'ENVIRONNEMENT.
|


Mime
View raw message