在 p:radioButton 的 for-Attribute 中引用 id
是否可以引用一个 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
。但由于
是一个 NamingContainer
,selectedFolder
位于另一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用绝对客户端 ID 而不是相对客户端 ID。
假设您有一个
,那么它的绝对客户端 ID 将为
form:radio
。它正是您在生成的 HTML 源中看到的值。要从另一个命名容器内部引用它,您需要在其前面添加(默认)命名容器分隔符:
前缀,使其变为:form:radio
。因此,应该这样做:与具体问题无关,您几乎在所有地方都使用
${}
而不是#{}
。虽然${}
在仅显示值中可能工作正常,但每当您提交表单时它就根本不起作用。您确实需要#{}
来代替。它不仅执行get
操作,还执行set
操作,而${}
只执行get
操作。只需在所有 JSF 页面中坚持#{}
即可。另请参阅:
Update 根据注释,尚不清楚命名容器全部放置在组合中的位置,但如果需要,您可以解析绝对客户端 ID复合体的动态变化如下:
Use an absolute client ID instead of a relative client ID.
Assuming that you've a
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: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 doget
, but also doesset
, while${}
only doesget
. 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: