Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As has been stated, the HTML name and id attributes are generated by the naming containers and based on the application namespace. This prevents collisions when controls are children of repeating controls (like a <code>UIData</code>) or a JSP is rendered twice in one page (like in a portlet environment). The id rendered to the HTML is the <strong>clientId</strong>.</p> <p>It is possible to hardcode or build the <code>clientId</code> manually, but this is a very fragile approach. It is better to use the component's <em>getClientId(FacesContext)</em> method; this is what the renderers use.</p> <p>A bean that can get the <code>clientId</code> for a bound component:</p> <pre><code>/** Request scope */ public class IdBean implements Serializable { private UIComponent mytext; public String getClientId() { return mytext.getClientId(FacesContext.getCurrentInstance()); } public UIComponent getMytext() { return mytext; } public void setMytext(UIComponent mytext) { this.mytext = mytext; } public List&lt;String&gt; getRows() { List&lt;String&gt; rows = new ArrayList&lt;String&gt;(); for (int i = 0; i &lt; 10; i++) { rows.add("row" + i); } return rows; } } </code></pre> <p>The view:</p> <pre><code> &lt;f:view&gt; &lt;h:form&gt; &lt;h:dataTable value="#{idBean.rows}" var="row"&gt; &lt;h:column&gt; &lt;h:outputLabel value="#{row}" /&gt; &lt;h:inputText binding="#{idBean.mytext}" onclick="foo('#{idBean.clientId}');" /&gt; &lt;/h:column&gt; &lt;/h:dataTable&gt; &lt;/h:form&gt; &lt;/f:view&gt; &lt;script type="text/javascript"&gt; function foo(name) { alert('You clicked '+name); } &lt;/script&gt; </code></pre> <p>The <em>mytext</em> control is rendered 10 times, so any code that emits its name must also be a child of the dataTable.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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