Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF button action triggered twice

I already asked this question in the WildFly forum but did not get any answers so far. So I´m trying here.

Since I upgraded from WildFly 8.1 to 8.2 I have problems with a commandButton inside a tabView connected to a 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 the 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");
    }
}

Clicking the "Inside" button triggers testInside() two times. The "Outside" button (outside of the tabView) behaves normally and triggers it´s method only once. Removing the tabView binding eliminates the problem. I´m using PrimeFaces 4.0.

Thanks for any ideas

Jan

like image 487
jpstrube Avatar asked Feb 02 '15 07:02

jpstrube


1 Answers

It's a Mojarra 'issue', introduced by a performance optimization fix in 2.2.7.

this is a Mojarra "issue", I've discovered it when working on RF-13920, it was introduced by JAVASERVERFACES-3193. The components that use binding are not recreated during a request to the server but their children are. With the original children still in place inserting the new children causes the "duplicate id" error.

So it looks like your button is added twice, but since you do not have an explicit id assigned, you do not get the duplicate id error... Might be interesting to give that a try (adding an explicit id)

The JSF specification states that binding should only be used in Request scope, so I don't think it should be treated as a bug if this fails in Conversation scope.

The last remark is the interesting one. As is posted in the next post on the jboss site:

But now I think I have a satisfying solution for this issue and I can confirm, that with request-scoped backing beans for the component binding the exception and duplicate id problem does not occur anymore, 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 a (say) conversation scoped bean. You just need to have a request-scoped bean for the binding attribute, which then can be referenced in EL and other beans.

Check also this post

like image 51
Kukeltje Avatar answered Sep 24 '22 13:09

Kukeltje