Andres Felipe
Andres Felipe

Reputation: 684

Issue in attribute for on h:outputLabel inside ui:repeat

I have following piece of code, i want to render radioButtons and labels for them. Due to the layout renderized by selectOneRadio and selectItem i decided to use plain HTML for the input radioButtons.

<h:panelGrid columns="6">
    <ui:repeat value="#{myBean.list}" var="item">
        <input id="#{item.innerList[0].id}" type="radio" name="radioItem" value="#{item.innerList[0].id}" />
        <h:outputLabel for="#{item.innerList[0].id}" value="#{item.label}" />
    </ui:repeat>
</h:panelGrid>

When trying to assign a label for them using outputLabel it renders the attribute for in HTML something like:

j_idt94:0:theidiassigned

The prependId flag in the tag form containing this code is set to false and in the documentation there is no such flag in the attributes of the other containing tags of the outputLabel.

Upvotes: 2

Views: 981

Answers (1)

McDowell
McDowell

Reputation: 108899

The ui:repeat component is a NamingContainer. It controls the client identifier of its children.

The for attribute on a h:outputLabel will generally look for a component with a matching component identifier or client identifier.

So, for this markup:

<foo:someNamingContainer id="x">
  <h:inputText id="foo" />
  <h:outputLabel for="foo" />
</foo:someNamingContainer>

...the label would emit the matching, namespaced identifier <label for="...:x:foo".

There is no matching JSF component with a matching id since you are using a straight XHTML <input> element.

Consider just using a XHTML <label> element instead.

Upvotes: 2

Related Questions