繁体   English   中英

在p:radioButton的for-Attribute中引用一个id

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

是否可以引用一个id来标识作为parents-parent-naming容器的子元素的组件?

例如:

<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>

我想从<p:radioButton>的for-attribute引用id selectedFolder 但是由于<ui:repeat>NamingContainer ,所以selectedFolder位于另一个NamingContainer ,我不知道该如何引用。 是否可以编写类似for="../selectedFolder"

我不能使用绝对ID引用,因为这是复合组件的一部分。 我还尝试在<ui:repeat>使用prependId="false" ,但这没有用。

使用绝对客户端ID而不是相对客户端ID。

假设您有一个

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

那么其绝对客户端ID将为form:radio 它就是您在生成的HTML源代码中看到的值。 要从另一个命名容器中引用它,您需要在其前面加上(默认)命名容器分隔符: ,以使其成为:form:radio 因此,应该这样做:

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

具体问题无关 ,几乎在所有地方都使用${}而不是#{} 尽管${}在仅显示值中可以正常使用,但是无论何时提交表单,它都根本不起作用。 您确实需要#{}来代替。 它不仅get ,而且set ,而${}get 只需在所有JSF页面上坚持#{}

也可以看看:


根据注释进行更新 ,尚不清楚命名容器在组合中的所有位置,但是如果需要,您可以按以下方式动态解析组合的绝对客户端ID:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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