0

I'm trying to create a table in JSF that has rows of inputs. Each row is its own display class and has the attributes it needs to display data. However, I need to have validator messages on each input, and I can't figure out how to get the id of the input to pass to the message in the 'for=' attribute. If I use a static ID, it throws the error for the entire column.

I tried dynamically creating the IDs with a function, or string concatenation, but it throws an error that the message component can't find the component to attach the 'for=' to.

I know dataTable is also an option, but I didn't see a way to get the ids there either. I'm new to JSF, so I feel like I must be missing something simple. I saw a post on grabbing NamedContainer ids, but I don't know if that works with a loop.

<table>
<tbody>
    <ui:repeat value="#{listOfItems}" var="item">
        <tr>
            <td>
                <h:outputLabel for="#{mainInputId}" <-!This id-->
                               value="label name"/>
                <h:message for=#{mainInputId} />
                <h:inputText id="#{mainInputId}"
                             validator="#{backingBean.validateInput}"
                             valueChangeListener="#{backingBean.inputChanged}"
                             value="#{item.inputValue}"
                             label="input label"
                             converterMessage="converter message">
                </h:inputText>
            </td>

            <td>
                <h:outputLabel for="#{secondInputId}"
                               value="label name"/>
                <h:message for=#{secondInputId} />
                <h:inputText id="#{secondInputId}"
                             validator="#{backingBean.validateInput}"
                             valueChangeListener="#{backingBean.inputChanged}"
                             value="#{item.secondInputValue}"
                             label="input label 2"
                             converterMessage="converter message">
                </h:inputText>
            </td>
        </tr>
    </ui:repeat>
</tbody>
<table>
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Eric
  • 1

0 Answers0