Search code examples
jsfjsf-2eluirepeat

Is it possible to use EL in ui:repeat?


Mojarra 2.1.29

I've read that usually it's not necessary to use EL to generate id-attribute dynamically. I also know that the id-attribute resolved at view-building phase. But in our projects we have to write some Selenium tests which are goign to use some html-attribute in the generated markup. So, I decided to specify the id-attribute dynamically. How can I do that for the following <ui:repeat>:

@ManagedBean
@SessionScoped
public class Bean{

    private List<Integer> values;
    //GET, SET
    public Bean(){
        values = Arrays.asList(1,2,5,7,8,9);
    }
}
<ui:repeat value="#{bean.values}" var="value">
    <h:outputText id="#{value}" /> <!-- not legal, resolved to null -->
</ui:repeat>

Maybe I should specify another attribute fo Selenium instead?


Solution

  • If you provide a fixed id like the following.

    <ui:repeat value="#{bean.values}" var="value">
        <h:outputText id="elementId" />
    </ui:repeat>
    

    The element you need will have ids generated as,

    parentId:0:elementId
    parentId:1:elementId
    parentId:2:elementId
    

    and so on.