2

由于一些自定义组件在其属性中需要一个 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>

和 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()

4

2 回答 2

5

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

 <a4j:commandButton value="test"
      action="#{sessionScope[beanName].delete}"/>
于 2009-11-23T14:31:19.350 回答
2
<a4j:commandButton value="test" action="#{bean[action]}" />

要传递的参数

<ui:param name="bean" value="#{sessionBean}" />
<ui:param name="action" value="delete" />

#{bean['delete']}如果您的操作名称是固定的,则可以使用。

于 2009-11-23T14:25:43.603 回答