JSF在ENTER键上调用了备份bean方法和reRender组件 [英] JSF invoke backing bean method and reRender components on ENTER key
问题描述
我的方法迄今只适用于IE 6和7,不在FF。这是inputText:
< h:inputText
value =#{applicantProductListBean.applicantNameFilterValue}
id =applicantNameFilterValueonkeypress =submitByEnter(event)>
< / h:inputText>
这是我调用的Javascript方法:
{pre>
function submitByEnter(e){
if(e.keyCode == 13){
// alert(Enter was pressed);
e.returnValue = false;
e.cancel = true;
document.getElementById(applicantProductListForm:refreshButton)。click();
}
}
如您所见,Javascript方法点击按钮刷新存在于页面上:
< a4j:commandButton value =刷新id =refreshButton
action =#{ApplicProductListBean.refreshData}
image =/ images / icons / refresh48x48.gif
reRender =table,croller>
< / a4j:commandButton>
refreshData方法不返回任何东西。如前所述,这只适用于IE 6和IE 7。
有谁知道为什么它不工作在FF?
我正在考虑的另一种方法是HotKey,它可以捕获ENTER的事件,但它只能调用Javascript,所以不合适。
通过RichFaces或简单的JSF来做到这一点的正确方法?
干杯!
更新:
BalusC稍作修改,该脚本的作用是:
if(event.preventDefault){
// Firefox
event.preventDefault();
} else {
// IE
event.returnValue = false;
}
尝试将JS块替换为:
function submitByEnter(e){
if(e.keyCode == 13){
e .preventDefault();
document.getElementById(applicantProductListForm:refreshButton)。click();
}
}
或更好,
function submitByEnter(e){
if(e.keyCode == 13){
document.getElementById(applicantProductListForm:refreshButton) 。点击();
返回false;
} else {
return true;
}
}
和输入的 onkeypress
by
onkeypress =return submitByEnter(event)
如果不行,请运行JS调试器 Firebug ,看看JS代码是否符合预期。
I have a datatable with as search fields. I want a method on the backing bean to be invoked when ENTER key is pressed, as well as the DataTable to be re-rendered.
My approach so far only works in IE 6, and 7, not in FF. This is the inputText:
<h:inputText
value="#{applicantProductListBean.applicantNameFilterValue}"
id="applicantNameFilterValue" onkeypress="submitByEnter(event)">
</h:inputText>
and this is the Javascript method I am invoking:
function submitByEnter(e){
if(e.keyCode==13){
// alert("Enter was pressed");
e.returnValue=false;
e.cancel=true;
document.getElementById("applicantProductListForm:refreshButton").click();
}
}
As you can see, the Javascript method clicks on the button refresh, which exists on the page:
<a4j:commandButton value="Refresh" id="refreshButton"
action="#{applicantProductListBean.refreshData}"
image="/images/icons/refresh48x48.gif"
reRender="table, scroller">
</a4j:commandButton>
The refreshData method does not return anything. As said before, this only works in IE 6 and IE 7.
Does anyone know why it does not work in FF?
An alternative I was considering was HotKey, which can indeed catch the event of ENTER, but it can only invoke Javascript, so it isn't appropriate.
Is the proper way to do this via RichFaces or plain JSF?
Cheers!
UPDATE:
Slightly modified the answer by BalusC, the script that works is:
if (event.preventDefault) {
// Firefox
event.preventDefault();
} else {
// IE
event.returnValue = false;
}
Try replacing the JS block by:
function submitByEnter(e){
if (e.keyCode == 13) {
e.preventDefault();
document.getElementById("applicantProductListForm:refreshButton").click();
}
}
or better,
function submitByEnter(e){
if (e.keyCode == 13) {
document.getElementById("applicantProductListForm:refreshButton").click();
return false;
} else {
return true;
}
}
and the input's onkeypress
by
onkeypress="return submitByEnter(event)"
If that doesn't work, run the JS debugger of Firebug to see if JS code behaves as expected.
这篇关于JSF在ENTER键上调用了备份bean方法和reRender组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!