Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF2 <h:message> unable to find component with ID
    primarykey
    data
    text
    <p>I am building a table using a &lt;ui:repeat&gt; tag, and its length is dynamic. Each row has a &lt;h:inputText&gt; field. When the form is submitted, it sets the values from the form into a hashmap. That all works great, except for the validation. I need to tell the &lt;h:message&gt; which input it belongs to using the "for" attribute. I've tried to create a unique ID per row, based on the name of the item being used to create the row. But the &lt;h:message&gt; tag remains empty when I submit an invalid input, and I get the following output on the servers log (JBoss 7.1):</p> <pre><code>[javax.enterprise.resource.webcontainer.jsf.renderkit] Unable to find component with ID nTAS in view. </code></pre> <p>Here is the XHTML:</p> <pre><code>&lt;ui:repeat var="item" ...&gt; ... &lt;h:inputText value="#{bean.chosenItems[item.name]}" id="n#{item.name}" &gt; &lt;f:validateLongRange minimum="0" maximum="10" /&gt; &lt;/h:inputText&gt; &lt;h:message for="n#{item.name}" /&gt; ... &lt;/ui:repeat&gt; </code></pre> <p>In order to at least get some kind of error message in the browser, I also added this near the top of my page, and it works:</p> <pre><code>&lt;h:messages styleClass="error" /&gt; </code></pre> <p>It displays this message:</p> <pre><code>j_idt13:j_idt17:1:n: Validation Error: Value is not of the correct type. </code></pre> <p>And that kind of shows part of the problem, since the ID is that strange code at the start of the message, and it starts with "n", but doesn't contain the item's name. If I look at the source in the browser, the ID is actually: <code>id="j_idt13:j_idt17:1:nTAS"</code></p> <p>If I look at other components, outside of the table, they also have cryptic IDs, apparently generated by JSF.</p> <p>And what is really weird is that when I input "asdf" a second time, and re-submit the form, it then calls the action method on the bean, instead of again failing during validation phase!! How can that be?!</p> <p>Thanks for any hints, John</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload