Tôi có đậu sau ủng hộ:Khi thêm thông báo khuôn mặt vào JSF, hành động của tôi không được thực hiện?
@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);
}
}
... Và trang xhtml sau:
<!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>
Đây là một trường hợp thử nghiệm tái sản xuất đơn giản. Khi bạn nhấp vào phân phối lại mà không có thông báo, mọi thứ hoạt động như mong đợi. Khi bạn nhấp vào nút phân phối lại, nó sẽ hiển thị thông báo thành công nhưng các trường nhập không được cập nhật. Tuy nhiên, trường đầu ra văn bản được cập nhật chỉ một lần.
Tôi đã thử sử dụng ngay = true trên cả hai nút và điều đó không ảnh hưởng đến điều này. Đây là một trường hợp rất đơn giản, tôi không thể hiểu tại sao nó không hoạt động.
Tôi đã thử điều này với tất cả các phiên bản gần đây của Mojarra bao gồm 2.1.3.
JSF impl/version gì? Không thể sao chép vấn đề này với Mojarra 2.1.1. – BalusC
Tôi đang sử dụng 2.1.2. Tôi cũng sử dụng richfaces 4 và primefaces cũng nằm trong bản mix. Tôi sẽ cố gắng loại bỏ một số điều đó và xem điều đó có giúp ích gì không. –
Kết quả tương tự chỉ với Mojarra 2.1.2 (FCS 20110610). –