4

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.

giliev
  • 2,938
  • 4
  • 27
  • 47
Real Chembil
  • 261
  • 2
  • 7
  • 23

2 Answers2

9

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.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
-1

As far I know JSF does not allow you to set dynamically id, and primefaces is JSF based.

Maybe the answer to this question can help you: Refer to JSF dynamically generated ids based on iteration index

Community
  • 1
  • 1
moretti.fabio
  • 1,128
  • 13
  • 32
  • The answer in the link you found contradicts the statement in your first paragraph. Do you actually understand what's going on here? – BalusC Jan 22 '14 at 19:37
  • I wrote the first paragraph, then started doing tests, then searched, then found the link, then put the link for pointing to a solution without deleting the first paragraph... so yes, a little confusion. – moretti.fabio Jan 23 '14 at 01:33