最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JSF: using onclick + actionListener together - Stack Overflow

programmeradmin4浏览0评论

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 mand 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:mandButton value="Upload" onclick="Richfaces.showModalPanel('p-id');return false;">
       <f:setPropertyActionListener target="#{bean.targetId}" value="#{item.id}" />   
   </a4j:mandButton>
 </rich:column>
 // more columns
</rich:dataTable>

Am I missing something here`?

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 mand 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:mandButton value="Upload" onclick="Richfaces.showModalPanel('p-id');return false;">
       <f:setPropertyActionListener target="#{bean.targetId}" value="#{item.id}" />   
   </a4j:mandButton>
 </rich:column>
 // more columns
</rich:dataTable>

Am I missing something here`?

Share Improve this question asked Apr 11, 2012 at 12:49 TheoTheo 3,1257 gold badges41 silver badges55 bronze badges 1
  • 3 return false; in your onclick prevents from continue the execute of a4j:mandButton , remove the return false; – Daniel Commented Apr 11, 2012 at 12:54
Add a ment  | 

1 Answer 1

Reset to default 4

The <a4j:mandButton> ponent 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.

The ponent'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 oute of the JavaScript code. If it returns false, then the default action will not be performed. This is what is happening in your case.

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.

发布评论

评论列表(0)

  1. 暂无评论