Stop JSF Event Chain

折月煮酒 提交于 2019-12-24 02:10:00

问题


I'm working on modifying a jsf-1.2 application for use on a tablet pc.

For that purpose I have made the rows of a table clickable to open the detail view of the rows contents, rather than have the user click on a link in that table (which is the case in the Desktop Version).

It works fine so far. Each row can, however, contain two rich-buttons that open a different link.

The contents of that link is opened in a new tab, like it's supposed to. My problem is, that the action event of the rowclick is activated in the original tab as well, which is not the intended behaviour.

What I want to do now is stop the event if one of the buttons in the row is clicked.

I know already, that the event of the butons is fired before the rowclick event. Is there a way to just cut the event chain at this point?


回答1:


This happens due to Event Bubbling. Try using Event.stop(event); in your commandButton as below.

<a4j:commandButton onclick="Event.stop(event);" action="#{myBean.myMethod())}" value="Show" />



回答2:


I don't know if you can break the chain - but even if it is possible (probably by throwing an exception) - I would recommend against it.

The proper (sadly) way to do it in an event-driven environment is to set some boolean indicator to be true when a handler for a button fires, and set it back to false when the handler finishes its job. In the handler for the row-clicked event, you need to check to see if the boolean is true - and only if it is false - continue with handling the row-clicked event.

A suggested name for the boolean: isRowButtownClicked

Disclaimer: I'm basing this answer on my knowledge in C# - I do not have any experience in GUI development in Java and specifically not in JSF.



来源:https://stackoverflow.com/questions/13808405/stop-jsf-event-chain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!