1

我想将 EL 一个 JSF 页面传递给 Facelets 模板。Facelets 模板只是将 EL 值理解为字符串值。如何将 EL 字符串传递给 Faceltes 模板?

page1.xml

<ui:include ..../>
<ui:param actionBeanMethod="#{EmployeeActionBean.deleteEmplayee(emp)}>

page2.xml

<ui:include ..../>
<ui:param actionBeanMethod="#{DepartmentActionBean.deleteDepartment(dep)}>

在确认模板.xml

    <a4j:commandLink onclick="#{rich:component('confirmation')}.show();return false">
        <h:graphicImage value="/img/delete.png" />
    </a4j:commandLink>
    <a4j:jsFunction name="submit" action="#{actionBeanMethod}"/>                    
    <rich:popupPanel id="confirmation" width="250" height="150">
       <f:facet name="header">Confirmation</f:facet>
       <h:panelGrid>
          <h:panelGrid columns="2">
             <h:graphicImage value="/img/alert.png" />
         <h:outputText value="Are you sure?" style="FONT-SIZE: large;" />
          </h:panelGrid>
          <h:panelGroup>
             <input type="button" value="OK" onclick="#{rich:component('confirmation')}.hide();submit();return false" />
         <input type="button" value="Cancel" onclick="#{rich:component('confirmation')}.hide();return false" />
          </h:panelGroup>
       </h:panelGrid>
    </rich:popupPanel>

我想动态改变 a4j:jsFuction 的动作。

    When page1.xhtm is call,
    <a4j:jsFunction name="submit" action="#{EmployeeActionBean.deleteEmplayee(emp)"/>

    When page2.xhtm is call,
    <a4j:jsFunction name="submit" action="#{DepartmentActionBean.deleteDepartment(dep)"/>

有可能吗?

4

1 回答 1

1

您不能将方法表达式作为<ui:param>值传递。它只接受值表达式。

您基本上需要创建一个自定义标记处理程序,它将值表达式重新解释为方法表达式。在当前的开源 JSF 组件/实用程序库中,OmniFaces <o:methodParam>是唯一能做到这一点的。

<o:methodParam name="methodParam" value="#{actionBeanMethod}" />
<a4j:jsFunction name="submit" action="#{methodParam}" />

您只需要将 Facelets 包含注册为 Facelets 标记文件并将其用作

<my:confirmationTemplate actionBeanMethod="#{EmployeeActionBean.deleteEmplayee(emp)}" />

另一种方法是改用复合组件。

于 2012-09-19T15:51:38.580 回答