JSF unable to set dynamic id for input component

后端 未结 1 1873
慢半拍i
慢半拍i 2021-01-16 14:39

my form looks like this:

\"enter

When the user clicks \"+ Add\" a new distanc

相关标签:
1条回答
  • 2021-01-16 15:13

    I need to be able to show individual "required" messages. Any ideas?

    For that you don't need to fiddle with IDs. JSF will do it for you. Just do

    <h:dataTable id="table" value="#{bean.distances}" var="distance"> 
        <h:column> 
            <h:inputText id="distance" value="#{distance.value}" required="true" />
            <h:message for="distance" />
        </h:column>
    </h:dataTable>
    

    This will end up in generated HTML like follows:

    <table id="form:table">
        <tr><td><input id="form:table:0:distance" /></td></tr>
        <tr><td><input id="form:table:1:distance" /></td></tr>
        <tr><td><input id="form:table:2:distance" /></td></tr>
        ...
    </table>
    

    Rightclick the page in browser and choose View Source to see it yourself.

    Any validation error will just be shown in the same row as the input.

    0 讨论(0)
提交回复
热议问题