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

发布于 2024-12-27 09:42:27 字数 1443 浏览 2 评论 0原文

是否可以引用一个 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>

我想从 中的 for-attribute 引用 id selectedFolder。但由于 是一个 NamingContainerselectedFolder 位于另一个 NamingContainer 中,我不知道看看如何引用它。是否可以编写类似 for="../selectedFolder" 的内容?

我不能使用绝对 id 引用,因为这是复合组件的一部分。 我还尝试在 中使用 prependId="false" ,但这不起作用。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

违心° 2025-01-03 09:42:27

使用绝对客户端 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 页面中坚持 #{} 即可。

另请参阅:


Update 根据注释,尚不清楚命名容器全部放置在组合中的位置,但如果需要,您可以解析绝对客户端 ID复合体的动态变化如下:

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

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" ... />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文