Ahmed Hassanien
Ahmed Hassanien

Reputation: 537

Primefaces command button action is not called for the second time

I have spring integrated with JSF and I am facing a strange behavior:

  1. I hit the command button the action method in the managed bean is hit successfully (I removed it in the below example).
  2. The Ajax update works perfect and the form is updated.
  3. I hit another button the action method now in the managed bean isn't hit.
  4. The panel is restored to the initial view and it freezes on this view.
  5. I can't get the form updated except if I refresh the page and these steps are repeated.

DealerInfo.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/default.xhtml">
    <ui:define name="content">
        <h:form id="toolBarForm">
            <p:toolbar style="margin-bottom:5px;">
                <p:toolbarGroup align="right">
                    <p:commandButton value="Add"
                        update=":toolBarForm" icon="ui-icon-plusthick" />
                    </p:toolbarGroup>
                </p:toolbar>
            <p:messages id="dealerInfoMessages" />
            <ui:include src="/pages/dealers/DealerMainInfo.xhtml" />
        </h:form>
    </ui:define>
</ui:composition>
</html>

pages/dealers/DealerMainInfo.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<ui:composition>
    <p:panel id="dealerMainInfoPanel" header="Dealer Main Info"
        style="margin-bottom:5px;">
        <h:panelGrid columns="2">
            <p:outputLabel for="dealerCode" value="Dealer Code" />
            <p:inputText id="dealerCode" required="true"
                value="#{dealerMainInfoBO.dealerCode}" style="width:200px;" />

            <p:outputLabel for="dealerName" value="Dealer Name" />
            <p:inputText id="dealerName" required="true"
                value="#{dealerMainInfoBO.dealerName}" style="width:200px;" />
        </h:panelGrid>
    </p:panel>
</ui:composition>
</html>

Update: I created a very simple single page and I noticed that when I remove the <h:head></h:head> tags the ajax works like a charm BUT without the fancy primefaces UI, and when I add the tags the ajax stop (this is normal cause <h:head></h:head> tags fetch all the needed JSs and CSSs), What Can I Do?

Example.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<f:view contentType="text/html">
    <h:head>
    </h:head>
    <h:body>
        <h:form id="toolBarForm">
            <p:toolbar style="margin-bottom:5px;">
                <p:toolbarGroup align="right">
                    <p:commandButton value="Add" update=":toolBarForm"
                        action="#{bean.add}" />
                </p:toolbarGroup>
            </p:toolbar>
            <p:messages id="operationDefinitionMessages" />
            <h:panelGrid columns="2">
                <p:outputLabel for="text" value="Text" />
                <p:inputText id="text" required="true" value="#{bean.text}" />
            </h:panelGrid>
        </h:form>
    </h:body>
</f:view>
</html>

My Environment

Upvotes: 0

Views: 1899

Answers (1)

Ahmed Hassanien
Ahmed Hassanien

Reputation: 537

In case anyone faces the same issue. I noticed that the Primefaces showcase is using JSF-Mojarra-2.1.22. I downgraded my JSF-Mojarra version from 2.2 to 2.1.22 and it worked like a charm.

If I am not wrong, I guess it should be reported to primefaces (if it isn't a current issue).

Upvotes: 1

Related Questions