Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add id(s) to primefaces components dynamically?

I have a requirement where I need to display components on the form which will be retrieved from the database. I am able to show the components with the help of datatable and ui repeat. I also need to include toolTip functionality for these components for which every component would require an ID. Is there any way we can add id(s) to the components dynamically.

<p:dataTable styleClass="borderless" id="rdResultTable" var="result"
    value="#{RequestBean.radioList}" rendered="#{not empty RequestBean.radioList}">

    <p:column style="width:150px;">
        <f:facet name="header">
            <h:outputText value=" " />
        </f:facet>
        <h:outputText value="#{msg[result.field_label]}"/>
    </p:column>
    <p:column>
        <f:facet name="header">
            <h:outputText value="" />
        </f:facet>
        <ui:repeat value="#{RequestBean.radioList}" var="itm">
            <p:inputText  value="#{itm.indFieldValue}"
            rendered="#{result.level_id==itm.level_id and  result.field_type=='textbox'}">
            </p:inputText>
        </ui:repeat>
    </p:column>
</p:dataTable>

Any help would be appreciated.

like image 292
Real Chembil Avatar asked Feb 17 '23 23:02

Real Chembil


1 Answers

You don't need to. JSF will automagically worry about setting the right relationship between <p:tooltip> and the target component within the same loop.

<ui:repeat ...>
    <p:inputText id="foo" ... />
    <p:tooltip for="foo" ... />
</ui:repeat>

Pull the JSF page in your webbrowser, rightclick and do View Source. You'll notice that the <ui:repeat> has already automatically prefixed the ID foo with the iteration index.

like image 75
BalusC Avatar answered Feb 23 '23 10:02

BalusC