Facelets:使用 ui:param 将 bean 名称传递给操作属性
由于某些自定义组件在其属性中需要 bean 名称(而不是 bean 实例),因此我需要在页面之间传递实际的 bean 名称。由于 bean 本身也由非自定义组件使用,因此我想避免使用额外的 ui:param
(如此处所述 在
是否可以使用 ui:param
提供的 bean 名称来指定组件的操作?
基本上我试图实现以下目标:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/template.xhtml">
<ui:param name="beanName" value="sessionBean"/>
...
</ui:composition>
而 template.xhtml 是
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
template="/someothertemplate.xhtml">
</ui:define name="somename">
<h:form>
<a4j:commandButton value="test" action="#{beanName.delete}"/>
</h:form>
</ui:define>
</ui:composition>
虽然删除方法已正确定义(使用 action="#{sessionBean.delete}" 验证),但上面的代码给了我
javax.faces.FacesException: #{beanName.delete}: javax.el.MethodNotFoundException: /template.xhtml @201,89 action="#{beanName.delete}": 找不到方法: sessionBean.delete()
Due to some custom components which expect a bean name (NOT the bean instance) in their attributes I need to pass the actual bean name between pages. As the bean itself is also used by non-custom components, I would like to avoid using additional ui:param
(like described here Passing action in <rich:modalPanel>) since it will essentially specify the same bean.
Is it possible to specify component's action using bean name provided with ui:param
?
Basically I am trying to achieve the following:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/template.xhtml">
<ui:param name="beanName" value="sessionBean"/>
...
</ui:composition>
and template.xhtml is
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
template="/someothertemplate.xhtml">
</ui:define name="somename">
<h:form>
<a4j:commandButton value="test" action="#{beanName.delete}"/>
</h:form>
</ui:define>
</ui:composition>
Although delete method is properly defined (verified with action="#{sessionBean.delete}"
) the above code gives me
javax.faces.FacesException: #{beanName.delete}: javax.el.MethodNotFoundException: /template.xhtml @201,89 action="#{beanName.delete}": Method not found: sessionBean.delete()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够通过其作用域引用该 bean:
You should be able to reference the bean via its scope:
传递的参数。
如果您的操作名称是固定的,则可以使用
#{bean['delete']}
The params to pass
you can use
#{bean['delete']}
if your action name is fixed.