2014-01-24 140 views
0

我有這個簡單的XHTML:從h獲取當前值:上Ajax請求輸入

<h:inputText id="input-nome" value="#{bean.value}" > 
    <f:ajax listener="#{bean.myListener}" event="keypress" > 
    </f:ajax> 
</h:inputText> 

和我的聽衆:

public void myListener(AjaxBehaviorEvent event){ 
    UIInput input = (UIInput) event.getSource(); 
    System.out.println(input.getValue()); 
System.out.println(getBean().getName()); 
} 

我想獲取當前類型值,但在監聽我例如,如果我輸入'a'和'b',那麼當我鍵入'ab'時,監聽器只會得到'a'的前一個值。如果我輸入'abc',我會得到'ab'。我怎樣才能獲得當前的輸入文本值?

+1

你已經有'value =「#{bean.value}」'那裏。爲什麼不只是做'System.out.println(value)'..? – BalusC

回答

0

將事件從keypress更改爲keyup。您可以添加execute="@this"execute="input-nome"

onkeyup:通過 輸入元素髮布密鑰時執行的客戶端回調。