2011-07-30 6 views
5

I次バッキングBeanがあります。JSFでfacesメッセージを追加すると、私のアクションは実行されませんか?

@ViewScoped 
@ManagedBean 
public class WeighFamilyBacking2 implements Serializable { 

private static final long serialVersionUID = 1L; 
private String[] children = new String[] { "Child1", "Child2", "Child3" }; 
private HashMap<String, Integer> newWeights; 

public WeighFamilyBacking2() { 
    newWeights = new HashMap<String, Integer>(); 
    for (String s : getChildren()) 
     newWeights.put(s, new Integer(0)); 
} 

public void distributeWeightsWithoutMessage(ActionEvent event) { 
    for (String s : newWeights.keySet()) { 
     newWeights.put(s, newWeights.get(s) + 1); 
    } 
} 

public void distributeWeights(ActionEvent event) { 
    for (String s : newWeights.keySet()) { 
     newWeights.put(s, newWeights.get(s) + 1); 
    } 

    FacesContext.getCurrentInstance().addMessage(null, 
      new FacesMessage("Succesful", "Weights redistributed.")); 
} 

public HashMap<String, Integer> getNewWeights() { 
    return newWeights; 
} 

public List<String> getChildren() { 
    return Arrays.asList(children); 
} 
} 

...そして、次のXHTMLページ:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html"> 
<h:body> 
    <h:form> 
     <ui:repeat var="child" value="#{weighFamilyBacking2.children}"> 
      <h:outputText value="#{child}" /> 
      <h:outputText value="#{weighFamilyBacking2.newWeights[child]}" /> - 
      <h:outputText value="#{weighFamilyBacking2.newWeights[child]}" /> - 
      <h:inputText id="oz" value="#{weighFamilyBacking2.newWeights[child]}" /> 
      <h:inputText id="lbs" 
       value="#{weighFamilyBacking2.newWeights[child]}" /> 
      <br /> 
     </ui:repeat> 

     <h:commandButton 
      actionListener="#{weighFamilyBacking2.distributeWeights}" 
      value="Redistribute" /> 


     <h:commandButton 
      actionListener="#{weighFamilyBacking2.distributeWeightsWithoutMessage}" 
      value="Redistribute Without Message" /> 
    </h:form> 
</h:body> 
</html> 

これは、単純な再現可能なテスト・ケースです。メッセージなしで再配布をクリックすると、事態は予想どおりに機能します。再配布ボタンをクリックすると成功メッセージが表示されますが、入力フィールドは更新されません。ただし、テキスト出力フィールドは1回だけ更新されます。

両方のボタンでimmediate = trueを使用しようとしましたが、これは影響しません。これは非常に単純なケースですが、なぜ動作しないのか理解できません。

私はこれを、2.1.3を含むすべての最新バージョンのMojarraで試しました。

+0

JSF impl/versionとは何ですか? Mojarra 2.1.1でこの問題を再現することはできません。 – BalusC

+0

私は2.1.2を使用しています。私もリッチフェイス4を使用しており、プライムフェイスも混在しています。私はそのうちのいくつかを削除して、それが役立つかどうかを見てみましょう。 –

+0

Mojarra 2.1.2(FCS 20110610)と同じ結果です。 –

答えて

1

これは別の<ui:repeat>の異常です。私は正確な根本原因を究明していないので、これが既にJSF guysに報告されているかどうかを確認し、必要なら報告するが、<ui:repeat><h:dataTable>に置き換えると動作すると言える。

<h:dataTable var="child" value="#{weighFamilyBacking2.children}"> 
    <h:column> 
     <h:outputText value="#{child}" /> 
     <h:outputText value="#{weighFamilyBacking2.newWeights[child]}" /> - 
     <h:outputText value="#{weighFamilyBacking2.newWeights[child]}" /> - 
     <h:inputText id="oz" value="#{weighFamilyBacking2.newWeights[child]}" /> 
     <h:inputText id="lbs" 
      value="#{weighFamilyBacking2.newWeights[child]}" /> 
    </h:column> 
</h:dataTable> 

多分<table>は意味がありません。これが本当に望ましくない場合は、Tomahawkの<t:dataList>、RichFacesの<rich:dataList>、PrimeFaces '<p:dataList>などで問題なく動作するかどうかを確認したい場合があります。追加のマークアップなしで子をレンダリングすることができます。

更新:私はissue 2157と報告しました。

+0

ありがとうBalusC!少なくとも私は狂っていないことを知っています。データテーブルはここでうまくいくでしょう。私がJSFのメンバーと何かを開いて報告しなければならないかどうか教えてください。テストケースを再現するのはかなり簡単です。リピート内のinputText要素にのみ影響するのは奇妙です。私はおそらくそれはrepeat内のinputText要素を特定することと関係があると思っていますか? –

+0

はい、同様の問題が、呼び出しアクション中に更新されたネストされた 'ui:repeat'のチェックボックスを使っていました。しかし、「FacesMessage」は含まれていませんでした。私はあなたの特定の問題の 'FacesMessage'の原因に興味があります。 – BalusC

関連する問題