jsf 将 selectOneMenu 值作为直接请求托管 bean 发送
我有一个 selectOneMenu 来管理两个对象 A 和 B 之间的关系。 其中 A 是固定的,B 可以通过菜单选择。
在表单上,提交 B 被发送到 bean 进行进一步处理(创建并保存关系对象 AToB)。
不工作的情况!
<h:selectOneMenu value=#{b}>
<!-- b items from bean -->
</h:selectOneMenu>
<h:commandButton action="#{bean.addBToSelA(b)}"/>
<managed-bean>
<description>B Entity Request Bean</description>
<managed-bean-name>b</managed-bean-name>
<managed-bean-class>B</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
工作的情况!
但是,如果 selectOneMenu 值是不同托管 bean 的嵌套属性,则它可以工作。 (例如 AToB)
<h:selectOneMenu value=#{aToB.b}>
<!-- b items from bean -->
</h:selectOneMenu>
<h:commandButton action="#{bean.addBToSelA(aToB.b)}"/>
<managed-bean>
<description>AToB Entity Request Bean</description>
<managed-bean-name>aToB</managed-bean-name>
<managed-bean-class>AToB</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
注意:如果我的“b”只是另一个请求托管 bean 的属性就足够了。
有人可以这么好心解释一下为什么吗?
I have a selectOneMenu that manages a relation between two Objects A and B.
Where A is fixed and B is selectable via the menu.
On form submit B is send to the bean for further processing (creating and saving relationship object AToB).
Not working case!
<h:selectOneMenu value=#{b}>
<!-- b items from bean -->
</h:selectOneMenu>
<h:commandButton action="#{bean.addBToSelA(b)}"/>
<managed-bean>
<description>B Entity Request Bean</description>
<managed-bean-name>b</managed-bean-name>
<managed-bean-class>B</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Working case!
But if the selectOneMenu value is a nested property of a different managed bean it works. (as example AToB)
<h:selectOneMenu value=#{aToB.b}>
<!-- b items from bean -->
</h:selectOneMenu>
<h:commandButton action="#{bean.addBToSelA(aToB.b)}"/>
<managed-bean>
<description>AToB Entity Request Bean</description>
<managed-bean-name>aToB</managed-bean-name>
<managed-bean-class>AToB</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Note: It is enough if my "b" is just a property of a different request managed bean.
Can someone be so kind and explain why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为JSF已经事先创建了bean实例。如果实例已存在于范围中,则它不会被模型值覆盖。从faces-config.xml 中删除
,它就可以正常工作了。与具体问题无关,您似乎已经在使用 JSF 2.x。为什么坚持使用旧的 JSF 1.x 风格的 faces-config.xml 配置?只需使用
@ManagedBean
注释(当然,仅在真正的支持 bean 类上)。Because JSF has already created the bean instance beforehand. It won't be overridden with the model value if the instance already exist in the scope. Remove the
<managed-bean>
fromfaces-config.xml
and it'll work just fine.Unrelated to the concrete problem, you seem to be already using JSF 2.x. Why sticking to the old JSF 1.x style
faces-config.xml
configuration? Just use@ManagedBean
annotation (on real backing bean classes only, of course).