2011-07-30 2 views
5

나는 다음과 같은 백업 콩이 있습니다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> 

이 간단한 재현 테스트 케이스입니다. 메시지없이 재분 j을 누르면 예상대로 작동합니다. 재분배 버튼을 클릭하면 성공 메시지가 표시되지만 입력 필드는 업데이트되지 않습니다. 그러나 텍스트 출력 필드는 한 번만 업데이트됩니다.

두 버튼 모두에서 즉치 = 참을 사용하려고 시도했지만이 영향을주지 않습니다. 이것은 매우 간단한 경우입니다. 왜 작동하지 않는지 이해할 수 없습니다.

2.1.3을 포함한 모든 최신 버전의 Mojarra에서 이것을 시도했습니다.

+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에보고되었는지를 확인하고 필요한 경우보고 할 수 있지만 <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! 적어도 나는 미치지 않는다는 것을 안다. datatable 가능성이 여기에 잘 작동합니다. JSF 사람들과 함께 뭔가를 열어보고해야하는지 알려주세요. 테스트 케이스를 재현하는 것은 상당히 쉽습니다. 반복되는 inputText 요소에만 영향을주는 것은 이상한 일입니다. 아마도 repeat 내 inputText 요소를 식별하는 것과 관련이 있다고 생각합니까? –

+0

예, 호출 액션 중에 업데이트 된 중첩 된'ui : repeat'의 체크 박스와 비슷한 문제가있었습니다. 그러나'FacesMessage'는 포함되어 있지 않았습니다. 나는 당신의 particuler 문제에서'FacesMessage'의 원인에 대해 궁금합니다. – BalusC

관련 문제