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で試しました。
JSF impl/versionとは何ですか? Mojarra 2.1.1でこの問題を再現することはできません。 – BalusC
私は2.1.2を使用しています。私もリッチフェイス4を使用しており、プライムフェイスも混在しています。私はそのうちのいくつかを削除して、それが役立つかどうかを見てみましょう。 –
Mojarra 2.1.2(FCS 20110610)と同じ結果です。 –