2011-07-30 25 views
5

我有以下支持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> 

這是一個簡單的重現測試用例。當您單擊沒有消息的重新分配時,事情按預期工作。當您點擊重新分配按鈕時,它會顯示成功消息,但輸入字段不會更新。但是,文本輸出字段只更新一次。

我已經嘗試在兩個按鈕上使用immediate = true,並且不影響此操作。這是一個非常簡單的例子,我不明白爲什麼它不起作用。

我已經嘗試過所有最新版本的Mojarra包括2.1.3。

+0

什麼是JSF impl/version?無法用Mojarra 2.1.1重現此問題。 – BalusC

+0

我正在使用2.1.2。我也在使用richfaces 4,並且primefaces也在混合中。我會嘗試刪除一些,看看是否有幫助。 –

+0

與Mojarra 2.1.2(FCS 20110610)相同的結果。 –

回答

1

這是另一個<ui:repeat>異常。我還沒有確定確切的根本原因,以便我可以檢查這是否已經報告給JSF guys,如果有必要報告它,但我可以告訴它,當我用<h:dataTable>替換<ui:repeat>時,它會起作用。

<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元素。我在想也許它與確定重複中的inputText元素有關? –

+0

是的,我在嵌套的'ui:repeat'中的複選框之前遇到類似的問題,這些問題在調用操作期間已更新。但是沒有涉及「FacesMessage」。我很好奇你的參與者問題中的'FacesMessage'的原因。 – BalusC

相關問題