重复的 ID。日本科学基金会
我的 JSF 有问题。谁能说为什么这不起作用?
<h:selectOneListbox
id="lang" size="5"
value="#{MbInstitution.node.lang}"
valueChangeListener="#{MbInstitution.changeLanguage}"
rendered="#{MbInstitution.view}"
>
<a4j:support event="onchange" reRender="shortDesc, fullDesc"/>
<f:selectItems value="#{MbInstitution.languagesByInstitute}"/>
</h:selectOneListbox>
<h:selectOneListbox
id="lang" size="5"
disabled="#{!MbInstitution.managingNew}"
value="#{MbInstitution.node.lang}"
rendered="#{!MbInstitution.view}"
>
<f:selectItems value="#{MbInstitution.availableLanguages}"/>
</h:selectOneListbox>
它说:“组件 instForm:lang 的重复 ID” 我知道我有 2 个具有相同 Id 的元素,但只有一个元素不渲染时才会渲染。所以,我不认为这会成为问题。其实这根本不是一个大问题,因为我不需要这个id,但是如果我需要的话我该怎么办?
I have a problem with JSF. Can anyone say why this doesn't work?
<h:selectOneListbox
id="lang" size="5"
value="#{MbInstitution.node.lang}"
valueChangeListener="#{MbInstitution.changeLanguage}"
rendered="#{MbInstitution.view}"
>
<a4j:support event="onchange" reRender="shortDesc, fullDesc"/>
<f:selectItems value="#{MbInstitution.languagesByInstitute}"/>
</h:selectOneListbox>
<h:selectOneListbox
id="lang" size="5"
disabled="#{!MbInstitution.managingNew}"
value="#{MbInstitution.node.lang}"
rendered="#{!MbInstitution.view}"
>
<f:selectItems value="#{MbInstitution.availableLanguages}"/>
</h:selectOneListbox>
It says: "duplicate Id for a component instForm:lang"
I know that i have 2 elements with same Id, but one is rendered only when another isn't. So, i didn't think it would be a problem. Actually it's not a big problem at all as i don't need this id, but what if i needed then what would i do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题是,这两个组件是该页面的 JSF 组件树的一部分。即使它们不能同时显示,它们也共享相同的 ID,这是 JSF 不允许的。
我看到三种解决方案可以解决您的问题:
第一个解决方案: 定义两个不同的 ID
第二个解决方案: 您可以按照 Wayne Young 的解释,使用 NamingContainer,它将为它们添加前缀ID 由 NamingContainer 的 ID 确定。
第三种解决方案:仅使用一个
,然后在Java代码中进行区别。Java代码:
Your problem is that these two components are part of the JSF Component tree for this page. And even if they cannot be displayed at the same time, they share the same ID, which is not allowed by JSF.
I see three solutions to solve your problem:
First solution: Define two differents ID
Second solution: You can, as explained by Wayne Young, use a NamingContainer, which will prefix their ID by the ID of the NamingContainer.
Third solution: Use only one
<h:selectOneListbox/>
and then make the difference in the Java code.Java code:
您必须使用不同的 ID 或将其放入另一个命名容器中。
UIComponent.setId() 的 Javadoc 说:
You'll have to use a different ID or put it in another naming container.
The Javadoc for UIComponent.setId() says: