JSF button action works twice

I already asked this question on the WildFly forum, but have not received an answer yet. Therefore, I am trying here.

Since I upgraded from WildFly 8.1 to 8.2, I have problems with commandButton inside the tabView connected to the bean.

Here is a simple JSF page:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:p="http://primefaces.org/ui"> <h:head></h:head> <h:body> <h:form> <p:tabView binding="#{testBean.tabView}"> <p:tab title="Tab"> <p:commandButton value="Inside" action="#{testBean.testInside}"/> </p:tab> </p:tabView> <p:commandButton value="Outside" action="#{testBean.testOutside}"/> </h:form> </h:body> </html> 

and bean:

 @Named @SessionScoped public class TestBean implements Serializable { private TabView tabView = new TabView(); public TabView getTabView() { return tabView; } public void setTabView(TabView tabView) { this.tabView = tabView; } public void testInside() { System.out.println("inside"); } public void testOutside() { System.out.println("outside"); } } 

Pressing the Inside button calls testInside() two times. The External button (outside the tabView) behaves normally and runs the method only once. Removing the tabView binding fixes the problem. I am using PrimeFaces 4.0.

Thanks for any ideas.

Jan

+5
source share
2 answers

This is the Mojarra issue introduced by the performance optimization patch in 2.2.7.

this is a question of "Mojara", I discovered it while working on RF-13920, it was introduced by JAVASERVERFACES-3193. Components that use binding are not recreated during a request to the server, but their children. When the original children are still in place, inserting new children causes a duplicate id error.

So it looks like your button is being added twice, but since you don't have an explicit identifier assigned, you won't get a duplicate id error ... You might be interested to try (add an explicit identifier)

The JSF specification states that binding should only be used in the request area, so I don’t think it should be considered as an error if this fails in the conversation area.

The last point is interesting. As reported in the next post on the jboss website:

But now I think that I have a satisfactory solution for this problem, and I can confirm that, with support for query support beans to bind the component, the exception and the problem of duplicating id no longer occurs even with Mojarra 2.2.8 from Wildfly-8.2.0 .Final!

This is even true if the rest of the logic for the page remains in the (say) bean conversation. For the binding attribute, you just need to specify a bean with the request, which can then be specified in EL and other beans.

Also check out this post

+7
source

You can try to do it another way. Use remoteCommand from the tab with the same commandButton action.

Then use the JavaScript function created by remoteCommand in the onclick event for commandButton.

Here is an example of using your code.
It is functional.

 <h:form> <p:remoteCommand id="myfun" name="myfun" action="#{testBean.testInside}" /> <p:tabView binding="#{testBean.tabView}"> <p:tab title="Tab"> <p:commandButton value="Inside" onclick="myfun();"/> </p:tab> </p:tabView> </h:form> 
-3
source

Source: https://habr.com/ru/post/1212416/


All Articles