0

I want to assign a dynamic value to an input in xhtml page. The ManagedBean contains 3 string attributes: customField1, customField2 and customField3

In the xhtml page I'm looping over a list of values to custruct components:

<ui:repeat  value="#{listBean.customFields}" var="item" varStatus="status">
<div >
    <p:outputLabel value="#{item.label}" />
    <br />
    <c:set var="test" value="#{'myBean.customField'.concat(status.index)}"/>

    <p:inputText value="#{test}"   />
</div>
</ui:repeat>

What I did for concatenation does not work since it concider that the whole expression is a String so it is unable to bind "#{test}" with the bean attribute.

You think it is possible to do that in jsf ?

thanks in advance !

5
  • cant you just do value="#{myBean.customField}#{status.index}" Commented Oct 27, 2015 at 17:14
  • I tried that..It does not work =>javax.el.PropertyNotFoundException: page.xhtml value="#{myBean.customField}#{status.index}": The class 'com.xxx.yyy.zzz.MyBean' does not have the property 'customField' Commented Oct 27, 2015 at 17:18
  • does customField have public getters/setters in your backing bean? Commented Oct 27, 2015 at 17:19
  • the backing bean contains only customField1, customField2 and customField3 with public getters and setters Commented Oct 27, 2015 at 17:22
  • Please ignore comments of j.con. He clearly came here along [java] tag (which Kukeltje rightfully removed) and is merely doing blind guesses. In future JSF questions, please don't use [java] tag. Commented Oct 27, 2015 at 18:52

1 Answer 1

1

Please try

<p:inputText value="#{myBean['customField'.concat(status.index)]}"/>
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer..that does not work : javax.el.PropertyNotFoundException: page.xhtml value="#{myBean.customField}#{status.index}": The class 'com.xxx.yyy.zzz.MyBean' does not have the property 'customField'. By the way, on the xhtml there was a warning about EL syntax starting at concat
Your error message doesn't match the code in answer.
Sorry ! you are right ! I think it works et does the binding correctly. However, since I have only customField1, customField2 and customField3 I put #{myBean['customField'.concat(status.index+1)]} and I got this error message : The class 'com.xxx.yyy.zzz.MyBean' does not have the property 'customField4'. Note that customFields contains only 3 elements... I do not understand why it is going until customField4 despite the length of the list = 3. When displaying the EL expression I got 1 , 2 and 3 ! I'm confused.. Why it is doing an additional iteration in the binding ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.