facelets:将带有ui:param的bean名称传递给action属性 [英] facelets: passing bean name with ui:param to action attribute
问题描述
由于某些自定义组件的属性中需要一个bean名称(不是bean实例),因此我需要在页面之间传递实际的bean名称.由于非定制组件也使用bean本身,因此我想避免使用其他ui:param
(如此处所述
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.
是否可以使用ui:param
提供的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>
和template.xhtml是
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>
尽管删除方法已正确定义(已通过action="#{sessionBean.delete}"
验证),但上面的代码为我提供了
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}":找不到方法:sessionBean.delete()
javax.faces.FacesException: #{beanName.delete}: javax.el.MethodNotFoundException: /template.xhtml @201,89 action="#{beanName.delete}": Method not found: sessionBean.delete()
推荐答案
您应该能够通过其作用域引用Bean:
You should be able to reference the bean via its scope:
<a4j:commandButton value="test"
action="#{sessionScope[beanName].delete}"/>
这篇关于facelets:将带有ui:param的bean名称传递给action属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!