简体   繁体   中英

Reference an id in the for-Attribute of p:radioButton

Is it possible to reference an id, that identifies a component that is a child of the parents-parent-naming container?

For example:

<div class="browserDiv"
            id="browserObjects">
            <p:selectOneRadio id ="selectedFolder" value="${cc.attrs.value.selectedObjectPath}" layout="custom">
                <f:selectItems value="${cc.attrs.value.objectList}"
                                var="object" itmeValue="${object.path}" itemLabel=""/>
            </p:selectOneRadio>

            <table>
                <ui:repeat var="object" value="${cc.attrs.value.objectList}" id ="repeat" varStatus="status" >
                        <tr>
                            <td class="checkBoxCell">
                                <p:radioButton id="radioButton_${object.path}" for="selectedFolder" itemIndex="#{status.index}"/>
                            </td>
                        </tr>
                </ui:repeat>
            </table>

        </div>

I want to reference the id selectedFolder from the for-attribute in <p:radioButton> . But since <ui:repeat> is a NamingContainer , selectedFolder lies in another NamingContainer and I don't see how this can be referenced. Is it possible to write something like for="../selectedFolder" ?

I cannot use absolute id-references because this is part of a composite component. I also tried using prependId="false" in <ui:repeat> , but that didn't work.

Use an absolute client ID instead of a relative client ID.

Assuming that you've a

<h:form id="form">
    <p:selectOneRadio id="radio" ...>
        ...
    </p:selectOneRadio>
</h:form>

then its absolute client ID would be form:radio . It's exactly the value which you see in the generated HTML source. To reference it from inside another naming container, you need to prefix it with the (default) naming container separator : so that it becomes :form:radio . So, this should do:

<p:radioButton for=":form:radio" ... />

Unrelated to the concrete problem, you're using ${} instead of #{} almost everywhere. While ${} may work fine in display-only values, it won't work at all whenever you submit the form. You'd really need #{} instead. It does not only do get , but also does set , while ${} only does get . Just stick to #{} throughout all JSF pages.

See also:


Update as per the comments, it's unclear where the naming containers are all placed in the composite, but if necessary you can resolve the absolute client ID of the composite dynamically as follows:

<p:radioButton for=":#{cc.clientId}:radio" ... />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM