[英]h:inputText does not fire ajax change event when changing its value from javascript
I have an input text field that changes its value in a javascript function when keyup event is fired and af:ajax that should fire for the change event: 我有一个输入文本字段,当触发keyup事件时,它会在javascript函数中更改其值; af:应该为change事件触发的ajax:
<h:inputText ... onkeyup="functionThantChangesTextValue(this);">
<f:ajax event="change" listener="#{someExpensiveCall()}".../>
</h:inputText>
The problem is that if I change programatically the value of the inputText in the javascript functionThantChangesTextValue , than the ajax does not trigger for the change event 问题是,如果我以编程方式更改javascript functionThantChangesTextValue中 inputText的值,那么ajax不会触发更改事件
I have tried this: 我试过这个:
function functionThantChangesTextValue(field) {
...
field.value = finalValue;
field.onchange();
}
and in this case the ajax event triggers fine, but I would not really want this to happen immediately after changing the value. 在这种情况下,ajax事件触发正常,但我不希望在更改值后立即发生这种情况。 What I really want, is the execute the ajax when changing the value and when loosing the focus. 我真正想要的是在更改值和失去焦点时执行ajax。
Eventually I managed to find some sort of solution using blur
& focus
events. 最终,我设法找到了一些使用blur
和focus
事件的解决方案。 On the focus
event I store the old inputTextValue value using storeOldValue
function and then I execute the someExpensiveCall
on the blur
event only if the current input text value is different from the old one. 在focus
事件中,我使用storeOldValue
函数存储旧的inputTextValue值,然后仅当当前输入文本值与旧的输入文本值不同时才在blur
事件上执行someExpensiveCall
。 In this way I try to simulate a change
event.. 通过这种方式,我尝试模拟change
事件..
<h:inputText ... onkeyup="functionThantChangesTextValue(this);">
<f:ajax event="focus" listener="#{storeOldValue()}"/>
<f:ajax event="blur" listener="#{someExpensiveCall()}".../>
</h:inputText>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.