2009-07-05 62 views
1

有一些方法可以在<rich:modalPanel>中傳遞動作。我想用「是」和「否」按鈕編寫簡單的彈出窗口,並且我想在不同的頁面中重複使用此彈出窗口,這就是爲什麼當按下「是」按鈕時需要調用不同的操作。有一種方法來傳遞<rich:modalPanel><a4j:actionparam>一些值:在<rich:modalPanel>中傳遞動作>

<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> 

但一些方式傳遞行動?

回答

1

我自己找到答案:)。也許這對別人會有幫助。

我已經使用Facelets完成了這項工作。當我包括彈出窗口,讓我的網頁我通過parametr它:

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

哪裏thisPageBean - 從調用什麼彈出豆。

然後在我彈出我寫道:

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

而與此我援引thisPageBean.someAtion。所有的魔法是${thisPageBean},這是必要的,我們$但沒有#

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> 

Basicly在模式面板的輸出將包含在中,testBean值

編輯(誤解)

我相信你會必須確定你這樣的模式面板:

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

而在你的管理豆你將不得不addChildren您模式面板動態與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; 
} 
+0

您將簡單的字符串或其他值傳遞給modalPanel,但我想要傳遞動作。我想在一個頁面中點擊「確定」按鈕彈出一個方法是complite,在其他頁面中的其他方法。我想通過這個方法來彈出。這將幫助我重用這個彈出窗口。 – aindl 2009-07-05 20:15:55

+0

哦,對不起,我誤解了你的問題。我會爲你考慮這個 – 2009-07-05 20:28:12

3

當您使用Facelets時,請看Rick Hightower's article和「傳遞動作」部分。這與你使用的基本方法是一樣的,但也傳遞了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]}"/> 

請注意,您使用#。

相關問題