Stop JSF Event Chain

2019-07-21 18:33发布

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?

2条回答
聊天终结者
2楼-- · 2019-07-21 19:16

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.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-07-21 19:22

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" />
查看更多
登录 后发表回答