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 EL expressions as custom component attributes
Date Wed, 06 Mar 2013 09:22:30 GMT
I do not succeed in passing EL expressions as attributes of a custom 
component used in a tag file.

I could not find a clear doc on how to do that with EL 2.2.

My use case is the following :

 1. a tag file taking attribute "context" as a parameter
 2. inside the tag file, using a home made custom component taking
    "bean" as a parameter

Context is an instance of an in-house class hierarchy. Bean is most 
often in this case #{context.selected}.

If I use my tag file the following way in a top level f:view :

|<my:tag  context="#{adminContext}"/>|

And inside my:tag definition :

|<my:custom  bean="#{context.selected}"/>|

In my custom component, I have tried accessors like

|public  ValueExpression  getBean()  {
     return  (ValueExpression)  getStateHelper().eval(PropertyKeys.bean);
}

public  void  setBean(ValueExpression  param)  {
     getStateHelper().put(PropertyKeys.bean,  param);
}|

and attribute declaration of custom component in taglib like :

|<attribute>
     <description>Nom du bean à afficher</description>
     <name>bean</name>
     <required>true</required>
     <deferred-value>
         <type>java.lang.Object</type>
     </deferred-value>
</attribute>|

and attribute declaration of the tag file like :

|<attribute>
     <name>context</name>
     <deferred-value>
         <type>java.lang.Object</type>
     </deferred-value>
     <required>true</required>
</attribute>|

I always get a "cast to ValueExpression exception" when calling getBean().

In a method of the custom component called by encodeBegin, I noticed 
that I can access the attribute using getValueExpression("bean").

It returns an instance of ContextAwareTagValueExpressionUEL. Its 
_wrapped attribute points to an instance of WrappedValueExpression, 
encapsulating a ValueExpressionImpl whose value (expr) is 
#{context.selected}. This instance of ValueExpressionImpl also has a 
VariableMapper handling the translation of "context" to "adminContext". 
Its expected type is javax.el.ValueExpression. This must cause my 
exception...

How can I make it works ?

Thanks in advance.

I am using MyFaces 2.1.9, CODI 1.0.5, OpenWebBeans 1.1.6, Tomcat 7.0.32.

(question also asked on 
http://stackoverflow.com/questions/15229708/el-expressions-as-custom-component-attributes




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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message