1

有一些方法可以在<rich:modalPanel>. 我想用“是”和“否”按钮编写简单的弹出窗口,并且我想在不同的页面中重用这个弹出窗口,这就是为什么我需要在按下“是”按钮时调用不同的操作。有一种方法可以通过<rich:modalPanel>with传递一些值<a4j:actionparam>

<a4j:commandButton value="See details…" id="det"
    reRender="popup_dataIdField, …">

    <rich:componentControl for="popup"
        operation="show" event="onclick" />

    <a4j:actionparam name="message" assignTo="#{popupBean.message}"
        value="#{myBean.message}" />                                        
</a4j:commandButton>

但是有什么方法可以通过行动吗?

4

3 回答 3

2

当您使用 Facelets 时,请查看Rick Hightower 的文章和“传递操作”部分。它与您使用的基本方法相同,但也在 bean 上传递方法。

例如:

<ui:include src="./WEB-INF/popup/popup.xhtml">
  <ui:param name="yesAction" value="save"/>
  <ui:param name="cancelAction" value="cancel"/>
  <ui:param name="backingBean" value="#{thisPageBean}"/>
</ui:include>

然后在弹出窗口中:

<a4j:commandButton id="yesButton" value="#{msgs.yesButton}"
     action="#{backingBean[yesAction]}"/>

请注意,您使用#。

于 2009-07-06T12:34:26.413 回答
1

我自己找到答案:)。也许它会对某人有所帮助。

我已经使用 Facelets 完成了这项工作。当我在我的页面中包含弹出窗口时,我将参数传递给它:

            <ui:include src="./WEB-INF/popup/popup.xhtml">
                <ui:param name="yesAction" value="${thisPageBean}" />
            </ui:include>  

where thisPageBean- 是弹出窗口调用的bean。

然后在我的弹出窗口中我写道:

 <a4j:commandButton id="yesButton" value="#{msgs.yesButton}"
                     action="#{yesAction.someAtion}"
 </a4j:commandButton>

有了这个我调用thisPageBean.someAtion. 所有的魔法都是${thisPageBean},它对我们来说是必要的,$但没有#

于 2009-07-05T20:22:42.233 回答
0

是的,我认为这样做没有任何问题。如果需要,可以使用我的代码:

<rich:modalPanel id="popup" width="261" height="386"  autosized="true"left="180" top="200" keepVisualState="true">
    <h:panelGrid id="panelGrid">
        <h:outputText value="#{PopupBean.output}" id="popupMessage"/>
            <a4j:commandLink action="#">
                <h:outputText value="Close" />
                <rich:componentControl for="popup" operation="hide" event="onclick"/>
            </a4j:commandLink>
    </h:panelGrid>
</rich:modalPanel>
<h:panelGrid columns="2">
    <a4j:commandLink action="#"  reRender="panelGrid">
        <h:outputText value="Yes" />
        <rich:componentControl for="popup" operation="show" event="onclick"/>
        <a4j:actionparam name="message" assignTo="#{PopupBean.output}" value="#{TestBean.input1}"/>
    </a4j:commandLink>
    <a4j:commandLink action="#" reRender="panelGrid">
         <h:outputText value="No" />
         <rich:componentControl for="popup" operation="show" event="onclick"/>
         <a4j:actionparam name="message2" assignTo="#{PopupBean.output}" value="#{TestBean.input2}"/>
    </a4j:commandLink>
 </h:panelGrid>

基本上,模态面板中的输出将包含 TestBean 中的值

编辑(误解)

我相信您将不得不像这样定义您的模态面板:

<rich:modalPanel id="popup" width="261" height="386"  autosized="true"left="180" top="200" keepVisualState="true"
    binding="#{PopupBean.popupPanel}">
</rich:modalPanel>

在您的托管 bean 中,您将不得不使用 java 动态地将儿童添加到您的模式面板中,如下所示:

public String action_PoppingThePanel() {
    HtmlCommandButton button = new HtmlCommandButton();
    button.setValue("Yes");
    String action = "#{TestBean.action_yes}";
    MethodExpression methodExpression =
            FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
            createMethodExpression(FacesContext.getCurrentInstance().getELContext(), action, null,
            new Class<?>[0]);

    button.setActionExpression(methodExpression);
    getPopupPanel().getChildren().add(button);
    button = new HtmlCommandButton();
    button.setValue("No");
    String action = "#{TestBean.action_no}";
    methodExpression =
            FacesContext.getCurrentInstance().getApplication().getExpressionFactory().
            createMethodExpression(FacesContext.getCurrentInstance().getELContext(), action, null,
            new Class<?>[0]);

    button.setActionExpression(methodExpression);
    getPopupPanel().getChildren().add(button);        
    getPopupPanel().setRendered(true);
    getPopupPanel().setShowWhenRendered(true);
    return null;
}
于 2009-07-05T18:31:20.897 回答