You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Paul Spencer <pa...@apache.org> on 2008/09/26 21:40:36 UTC

How to set a component value to an EL Expression in Java?

I need to dynamically add a child component inside a bean. I have access 
to the component via a binding and have successfully added the child 
component.  What I have not been able to do is set the value of the 
child component to an EL Expresion so it is resolve by JSF 1.2.

The equivalent tag for the child component is:
   <tr:inputText value="#{foo.bar}"/>

So far I have:
    CoreInputText childComponent;
    childComponent = (CoreInputText) 
application.createComponent(CoreInputText.COMPONENT_TYPE);
    // Set the value to an EL Expression
    childComponent.setValue("#{foo.bar}"); // Does not work


Suggestions?

Paul Spencer


Re: How to set a component value to an EL Expression in Java?

Posted by Paul Spencer <pa...@apache.org>.
Andrew,
This works.

Thank you.

Paul Spencer
Andrew Robinson wrote:
> Oops, here is a better version:
> 
> FacesContext facesContext = FacesContext.getCurrentInstance();
> CoreInputText childComponent = childComponent = (CoreInputText)
>   facesContext.getApplication().createComponent(CoreInputText.COMPONENT_TYPE);
> ValueExpression ve = facesContext.getApplication().getExpressionFactory()
>  .createValueExpression(facesContext.getELContext(), "#{foo.bar}",
>     Object.class);
> childComponent.setValueExpression("value", ve);
> 
> 
> On Fri, Sep 26, 2008 at 2:02 PM, Andrew Robinson
> <an...@gmail.com> wrote:
>> JSF 1.2 code:
>>
>> CoreInputText childComponent;
>>  childComponent = (CoreInputText)
>> application.createComponent(CoreInputText.COMPONENT_TYPE);
>> FacesContext facesContext = FacesContext.getCurrentInstance();
>> ValueExpression ve = facesContext.getApplication().getExpressionFactory()
>>  .createValueExpression(facesContext.getELContext(), "#{foo.bar}",
>> Object.class);
>> childComponent.setValueExpression(ve);
>>
>> -Andrew
>>
>> On Fri, Sep 26, 2008 at 1:51 PM, Shane Petroff <sh...@mayet.ca> wrote:
>>> Paul Spencer wrote:
>>>> I need to dynamically add a child component inside a bean. I have access
>>>> to the component via a binding and have successfully added the child
>>>> component.  What I have not been able to do is set the value of the child
>>>> component to an EL Expresion so it is resolve by JSF 1.2.
>>>>
>>>> The equivalent tag for the child component is:
>>>>  <tr:inputText value="#{foo.bar}"/>
>>>>
>>>> So far I have:
>>>>   CoreInputText childComponent;
>>>>   childComponent = (CoreInputText)
>>>> application.createComponent(CoreInputText.COMPONENT_TYPE);
>>>>   // Set the value to an EL Expression
>>>>   childComponent.setValue("#{foo.bar}"); // Does not work
>>>>
>>> ValueBinding vb = application.createValueBinding(elExpression);
>>> vb.setValue(context, value);
>>>
>>> Will work, but iirc, this is deprecated, and there is an alternate for 1.2,
>>> namely ValueExpression
>>>
>>> Shane
>>>
>>>
>>>
>>> --
>>> Shane
>>>
>>>
> 


Re: How to set a component value to an EL Expression in Java?

Posted by Andrew Robinson <an...@gmail.com>.
Oops, here is a better version:

FacesContext facesContext = FacesContext.getCurrentInstance();
CoreInputText childComponent = childComponent = (CoreInputText)
  facesContext.getApplication().createComponent(CoreInputText.COMPONENT_TYPE);
ValueExpression ve = facesContext.getApplication().getExpressionFactory()
 .createValueExpression(facesContext.getELContext(), "#{foo.bar}",
    Object.class);
childComponent.setValueExpression("value", ve);


On Fri, Sep 26, 2008 at 2:02 PM, Andrew Robinson
<an...@gmail.com> wrote:
> JSF 1.2 code:
>
> CoreInputText childComponent;
>  childComponent = (CoreInputText)
> application.createComponent(CoreInputText.COMPONENT_TYPE);
> FacesContext facesContext = FacesContext.getCurrentInstance();
> ValueExpression ve = facesContext.getApplication().getExpressionFactory()
>  .createValueExpression(facesContext.getELContext(), "#{foo.bar}",
> Object.class);
> childComponent.setValueExpression(ve);
>
> -Andrew
>
> On Fri, Sep 26, 2008 at 1:51 PM, Shane Petroff <sh...@mayet.ca> wrote:
>> Paul Spencer wrote:
>>>
>>> I need to dynamically add a child component inside a bean. I have access
>>> to the component via a binding and have successfully added the child
>>> component.  What I have not been able to do is set the value of the child
>>> component to an EL Expresion so it is resolve by JSF 1.2.
>>>
>>> The equivalent tag for the child component is:
>>>  <tr:inputText value="#{foo.bar}"/>
>>>
>>> So far I have:
>>>   CoreInputText childComponent;
>>>   childComponent = (CoreInputText)
>>> application.createComponent(CoreInputText.COMPONENT_TYPE);
>>>   // Set the value to an EL Expression
>>>   childComponent.setValue("#{foo.bar}"); // Does not work
>>>
>>
>> ValueBinding vb = application.createValueBinding(elExpression);
>> vb.setValue(context, value);
>>
>> Will work, but iirc, this is deprecated, and there is an alternate for 1.2,
>> namely ValueExpression
>>
>> Shane
>>
>>
>>
>> --
>> Shane
>>
>>
>

Re: How to set a component value to an EL Expression in Java?

Posted by Andrew Robinson <an...@gmail.com>.
JSF 1.2 code:

CoreInputText childComponent;
  childComponent = (CoreInputText)
application.createComponent(CoreInputText.COMPONENT_TYPE);
FacesContext facesContext = FacesContext.getCurrentInstance();
ValueExpression ve = facesContext.getApplication().getExpressionFactory()
  .createValueExpression(facesContext.getELContext(), "#{foo.bar}",
Object.class);
childComponent.setValueExpression(ve);

-Andrew

On Fri, Sep 26, 2008 at 1:51 PM, Shane Petroff <sh...@mayet.ca> wrote:
> Paul Spencer wrote:
>>
>> I need to dynamically add a child component inside a bean. I have access
>> to the component via a binding and have successfully added the child
>> component.  What I have not been able to do is set the value of the child
>> component to an EL Expresion so it is resolve by JSF 1.2.
>>
>> The equivalent tag for the child component is:
>>  <tr:inputText value="#{foo.bar}"/>
>>
>> So far I have:
>>   CoreInputText childComponent;
>>   childComponent = (CoreInputText)
>> application.createComponent(CoreInputText.COMPONENT_TYPE);
>>   // Set the value to an EL Expression
>>   childComponent.setValue("#{foo.bar}"); // Does not work
>>
>
> ValueBinding vb = application.createValueBinding(elExpression);
> vb.setValue(context, value);
>
> Will work, but iirc, this is deprecated, and there is an alternate for 1.2,
> namely ValueExpression
>
> Shane
>
>
>
> --
> Shane
>
>

Re: How to set a component value to an EL Expression in Java?

Posted by Shane Petroff <sh...@mayet.ca>.
Paul Spencer wrote:
> I need to dynamically add a child component inside a bean. I have 
> access to the component via a binding and have successfully added the 
> child component.  What I have not been able to do is set the value of 
> the child component to an EL Expresion so it is resolve by JSF 1.2.
>
> The equivalent tag for the child component is:
>   <tr:inputText value="#{foo.bar}"/>
>
> So far I have:
>    CoreInputText childComponent;
>    childComponent = (CoreInputText) 
> application.createComponent(CoreInputText.COMPONENT_TYPE);
>    // Set the value to an EL Expression
>    childComponent.setValue("#{foo.bar}"); // Does not work
>

ValueBinding vb = application.createValueBinding(elExpression);
vb.setValue(context, value);

Will work, but iirc, this is deprecated, and there is an alternate for 
1.2, namely ValueExpression

Shane



-- 
Shane