我有一個簡單的表單,帶有一個inputText和2個commandButtons。 inputText顯示支持bean的值正確,但是當我第一次改變該值時,set方法不被調用,因此表單提交一個空值。當我再次更改它時,則調用set方法,並且一切正常。什麼原因,我該如何解決?<h:inputText值不更新
<h:panelGroup id="chatId">
<h:panelGrid rendered="#{chat.validUser == true}">
<h:form id="sendMsgForm" >
<h:panelGroup id="chatId2">
<h:inputText id="chatInput" value="#{chat.msgTo}" autocomplete="off" >
<f:ajax execute="@this @form" />
</h:inputText>
<h:commandButton value="Send" id="sendButton" action="#{chat.send}">
<f:ajax render=":chatLogId :chatId" />
</h:commandButton>
<h:commandButton value="Bye" action="#{chat.bye}">
<f:ajax render=":chatLogId :chatId :chatUserId" />
</h:commandButton>
</h:panelGroup>
</h:form>
</h:panelGrid>
</h:panelGroup>
的支持bean代碼:
@SessionScoped
public class Chat implements Serializable, ActionListener, ValueChangeListener {
private String msgTo = "Start typing...";
private boolean validUser = false;
public void bye() {
validUser = false;
tc.disconnect();
}
public void send() {
try {
tc.sendMessage(msgTo);
setMsgTo("");
} catch (Exception e) {
e.printStackTrace();
}
}
// ...
但他在第一次和第二次更改輸入字段值。所以它應該在兩個時間都有效。或者我錯過了什麼? – 2011-03-30 06:32:09
感謝您對Matt和BalusC的回覆。我試圖在commandButton中只有f:ajax,並且只是inputText,但行爲仍然相同。當我第一次改變輸入字段並按下回車鍵,或者點擊按鈕時,輸入字段被重置爲默認的「開始輸入...」。第二次,我改變了輸入字段,一切正常。這就像我的輸入是第一次在別的地方。謝謝。 Binh – Binh 2011-03-30 10:14:39
這些更改是否重新發布到服務器? – BalusC 2011-03-30 11:11:16