JSF:使用的onclick +的ActionListener在一起 [英] JSF: using onclick + actionListener together

查看:777
本文介绍了JSF:使用的onclick +的ActionListener在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想按钮点击执行JavaScript,并在同一时间在底层设置属性。执行JS code工作,但属性的动作监听不会被调用。当我删除了onclick属性,但属性是在底层单击命令按钮时设置。我也试着使用一个ActionListener。但同样的问题。这是我的JSF code:

I'm trying to execute JavaScript on button click and setting properties in the backing at the same time. Executing JS code works, but the property action listener does not get called. When I remove the onclick attribute, however, the properties are set in the backing when clicking the command button. I've also tried using an actionListener. But same issue. Here's my JSF code:

<rich:dataTable value="#{bean.items}" var="item">
  <rich:column>
    <a4j:commandButton value="Upload" onclick="Richfaces.showModalPanel('p-id');return false;">
       <f:setPropertyActionListener target="#{bean.targetId}" value="#{item.id}" />   
   </a4j:commandButton>
 </rich:column>
 // more columns
</rich:dataTable>

我缺少的东西here`?

Am I missing something here`?

推荐答案

&LT; A4J:的commandButton&GT; 组件生成一个HTML &LT;输入TYPE =提交&GT; 连同一堆JS code的AJAX魔术是不相关的当前问题的元素

The <a4j:commandButton> component generates a HTML <input type="submit"> element along with a bunch of JS code for the ajax magic which is not relevant to the current question.

组件的的onclick 属性获取生成的非常相同的HTML元素的的onclick 属性。该的onclick 属性通常是指一些JavaScript code这得到执行时,HTML DOM 点击事件被激发的特别是HTML元素。该事件被触发时,立即终端用户点击HTML元素,这发生的 的HTML元素的默认操作(提交父窗体)被调用之前。更有甚者,默认操作可以通过JavaScript的code布尔结果进行控制。如果返回,则默认操作将不被执行。这就是发生在你的情况。

The component's onclick attribute get generated as the onclick attribute of the very same HTML element. The onclick attribute usually refers some JavaScript code which get executed when the HTML DOM click event is fired on the particular HTML element. This event is fired immediately when the enduser clicks the HTML element and this takes place before the HTML element's default action (submitting the parent form) is invoked. Even more, the default action can be controlled by the boolean outcome of the JavaScript code. If it returns false, then the default action will not be performed. This is what is happening in your case.

如果你想同时调用JavaScript的code。在的onclick 属性的的的HTML的默认操作&LT;输入类型=提交&GT; 元素,那么你必须返回,或者只是删除返回false; 片完全

If you want to invoke both the JavaScript code in the onclick attribute and the default action of the HTML <input type="submit"> element, then you have to return true, or just to remove the return false; piece altogether.

这篇关于JSF:使用的onclick +的ActionListener在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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