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: EL expressions as custom component attributes
Date Wed, 06 Mar 2013 10:13:34 GMT
Well,

reading my message again, I found that I still does not properly explain 
my problem.

It is not really to pass a bean using an EL expression.

To do that, you just declare getBean/setBean as returning/taking as 
parameter an Object, and that's done.

My custom component generates itself some custom EL.

So, I need to grab the ValueExpression used to pass this bean.

I found that I can do so using getValueExpression("bean") in my custom 
component method.
However, I found no clean way (I mean, other than reflection) to get a 
hand on the wrapper VariableMapper, to perform mappings before reusing 
the expression or to specify to use this mapper when evaluating my 
custom expressions.

In my example, my custom component generated EL expressions such as 
#{context.selected.attribute1} . Without proper VariableMapper, 
evaluation just fails as "context" is not defined.

Thanks in advance for your patience.

Ludovic
On 06/03/2013 10:22, l.penet@senat.fr wrote:
>
> 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  (ValueExpress
> ion)  getStateHelper().eval(PropertyKeys.bean);
> }
>
> public  void  setBean<
> span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 14px; vertical-align:
baseline; background-color: transparent; color: rgb(0, 0, 0); background-position: initial
initial; background-repeat: initial initial;">(ValueExpression  param)  {
>      getStateHelper().put(P
> ropertyKeys.bean,  param<
> span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-size: 14px; vertical-align:
baseline; background-color: transparent; color: rgb(0, 0, 0); background-position: initial
initial; background-repeat: initial initial;">);
> }|
>
> 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