JSF在ENTER键上调用了备份bean方法和reRender组件 [英] JSF invoke backing bean method and reRender components on ENTER key

查看:133
本文介绍了JSF在ENTER键上调用了备份bean方法和reRender组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表作为搜索字段。我想要在按下ENTER键时调用支持bean上的方法,以及要重新呈现的DataTable。



我的方法迄今只适用于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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆