在JSF中添加faces消息时,我的动作不会执行?

jr.*_*jr. 5 jsf-2

我有以下支持bean:

@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);
}
}
Run Code Online (Sandbox Code Playgroud)

...以及以下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>
Run Code Online (Sandbox Code Playgroud)

这是一个简单的可重复测试用例.当您单击没有消息的重新分发时,事情按预期工作.单击重新分发按钮时,它将显示成功消息,但不会更新输入字段.但是,文本输出字段只更新一次.

我尝试在两个按钮上使用immediate = true,但这并不影响这一点.这是一个非常简单的案例,我无法理解为什么它不起作用.

我已经尝试过所有最新版本的Mojarra,包括2.1.3.

Bal*_*usC 1

这是另一个<ui:repeat>异常现象。我还没有确定确切的根本原因,以便我可以检查这是否已经报告给JSF 人员,并在必要时报告它,但我可以说,当我<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>
Run Code Online (Sandbox Code Playgroud)

也许 a<table>在语义上对你来说不正确。如果这确实是不可取的,您可能需要检查它是否可以正常使用 Tomahawk's <t:dataList>、 RichFaces' <rich:dataList>、 PrimeFaces'<p:dataList>等,每个都支持在没有额外标记的情况下渲染子项。

更新:我将其报告为问题 2157