facelets:使用ui:param将bean名称传递给action属性

oro*_*rom 2 jsf facelets ajax4jsf

由于某些自定义组件在其属性中需要bean名称(不是bean实例),我需要在页面之间传递实际的bean名称.由于bean本身也被非自定义组件使用,我想避免使用额外的ui:param(如此处所描述的在<rich:modalPanel>中传递操作),因为它基本上指定了相同的bean.

是否可以使用提供的bean名称指定组件的操作ui:param

基本上我试图实现以下目标:

<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>
Run Code Online (Sandbox Code Playgroud)

和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>
Run Code Online (Sandbox Code Playgroud)

虽然删除方法已正确定义(验证action="#{sessionBean.delete}"),但上面的代码给了我

javax.faces.FacesException:#{beanName.delete}:javax.el.MethodNotFoundException:/template.xhtml @ 201,89 action ="#{beanName.delete}":找不到方法:sessionBean.delete()

McD*_*ell 5

您应该能够通过其范围引用bean:

 <a4j:commandButton value="test"
      action="#{sessionScope[beanName].delete}"/>
Run Code Online (Sandbox Code Playgroud)