简体   繁体   English

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

[英]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? 是否可以引用一个id来标识作为parents-parent-naming容器的子元素的组件?

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> . 我想从<p:radioButton>的for-attribute引用id selectedFolder But since <ui:repeat> is a NamingContainer , selectedFolder lies in another NamingContainer and I don't see how this can be referenced. 但是由于<ui:repeat>NamingContainer ,所以selectedFolder位于另一个NamingContainer ,我不知道该如何引用。 Is it possible to write something like for="../selectedFolder" ? 是否可以编写类似for="../selectedFolder"

I cannot use absolute id-references because this is part of a composite component. 我不能使用绝对ID引用,因为这是复合组件的一部分。 I also tried using prependId="false" in <ui:repeat> , but that didn't work. 我还尝试在<ui:repeat>使用prependId="false" ,但这没有用。

Use an absolute client ID instead of a relative client ID. 使用绝对客户端ID而不是相对客户端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 . 那么其绝对客户端ID将为form:radio It's exactly the value which you see in the generated HTML source. 它就是您在生成的HTML源代码中看到的值。 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 . 要从另一个命名容器中引用它,您需要在其前面加上(默认)命名容器分隔符: ,以使其成为: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 . 它不仅get ,而且set ,而${}get Just stick to #{} throughout all JSF pages. 只需在所有JSF页面上坚持#{}

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

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

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

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