0

解決策が見つからないという問題に直面しています...次のようなselectManyChoiceコンポーネントがあります。

<af:selectManyChoice value="#{bindings.my_VO1.inputValue}" 
                     label="myLabel" id="smc1"
                     binding="#{pageFlowScope.myBean.myMultiSelection}"
                     autoSubmit="true">
  <f:selectedItems value="#{bindings.my_VO1.items}" id="si1"/>
</af:selectManyChoice>

値を取得するために、次のような 2 つのボタンを使用してテストしました。

<af:commandButton text="First Button" 
                  id="cb1" 
                  action="#{pageFlowScope.myBean.saveSelection}>
  <af:fileDownloadActionListener method="#{pageFlowScope.myBean.exportReport}"/>
</af:commandButton>

と:

<af:commandButton text="Second Button" 
                  id="cb2" 
                  action="#{pageFlowScope.myBean.saveSelection}/>

2 番目のボタンは、選択された値を正常に取得し、画面に出力できます。ただし、最初のボタンはできませんでした。次のコード行で myMultiSelection.getValue() を呼び出そうとすると、常に NullPointerException がスローされます。

public String saveSelection() {
    if (myMultiSelection.getValue() != null) {

それらの唯一の違いは、fileDownloadActionListener タグです。そのタグが最初のボタンの内部動作に影響を与えていたのだろうか...しかし、ボタンの目的は選択した値に基づいてpdfファイルを生成し、ブラウザにそのファイルをダウンロードさせることであるため、それでもそのタグが必要です. 誰かが私を正しい方向に向けることができますか?

4

1 に答える 1

2

この方法で試すことができます: 2 番目のボタンを使用し、アクション リスナーで fileDownloadActionListener を呼び出すだけです。そうすれば、選択した値が正しいかどうかを確実に知ることができます。

例 : http://adfwithejb.blogspot.be/2012/08/calling-affiledownloadactionlistener_2.html

編集: JS を使用して actionlistener を呼び出す代わりに、次の方法で実行できます。

これらをあなたのページに追加してください:

<af:commandButton text="Hidden Button" binding="#{pageFlowScope.myBean.btnHiddenButton}"
                  id="cb1" visible="false">
  <af:fileDownloadActionListener method="#{pageFlowScope.myBean.exportReport}"/>
</af:commandButton>

<af:commandButton text="Visible Button" 
                  id="cb2" 
                  action="#{pageFlowScope.myBean.saveSelection}/>

次に、Bean で saveSelection メソッドに移動し、正しいデータを取得するためにいくつかのことを行います。その後、これを追加します:

ActionEvent event = new ActionEvent(btnHiddenButton);
event.queue();  

これにより、非表示のボタンを押さなくてもトリガーされます。(もちろん、バインディングがあることを確認してください)

于 2012-11-05T11:26:59.760 に答える