2009-07-05 3 views
1

<rich:modalPanel>にアクションを渡す方法がいくつかあります。私は "はい"と "いいえ"ボタンで簡単なポップアップを書いて、別のページでこのポップアップを再利用したいので、 "はい"ボタンを押したときに別のアクションが呼び出される必要があります。<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> 

しかし、アクションを渡すためにいくつかの方法である:あり<a4j:actionparam><rich:modalPanel>に何らかの値を渡す方法はありますか?

答えて

1

は私が自分で答えを見つける:)。多分それは誰かのために役立つでしょう。

私はこれをFaceletsを使って行っています。私は私のページへのポップアップが含まれていたとき、私はそれにparametrを渡す:

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

thisPageBean - ポップアップが呼び出されたものとはBeanです。

はその後、私のポップアップに私が書いた:

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

そして、あなたの管理Beanにあなたがモーダルに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に渡しますが、私は動作を渡します。ポップアップで「OK」ボタンをクリックすると、あるページが他のページの他のメソッドでコンプライアントになっていました。私はこのメソッドをポップアップに渡したい。このポップアップを再利用するのに役立ちます。 – aindl

+0

ああ、私はあなたの質問を誤解して申し訳ありません。私はあなたのためにこれを調べます –

+0

迅速な応答ありがとう、しかし私は簡単な解決策を見つける:)。 atopを参照してください。 – aindl

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]}"/> 

注意。

+0

それは豆を渡していませんか?どのようにしてBeanとActionの両方を渡すことができますか? – nikagra

+0

まずは試してみてください。角括弧はアクションを許可します。 – Damo

関連する問題