jsfprimefacesremotecommand

p:remoteCommand does not invoke the declared action method


Web page :

<html xmlns="http://www.w3.org/1999/xhtml"   
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui">

<h:body>

    <ui:composition template="../../Template/template.xhtml">

        <ui:define name="content">

            <h:form>

                <h:outputText id="montest" value="#{ProviderLogin.i}"/>

                <button class="ZWButtonActionIntervention pfButtonWhite" type="button" onclick="testpageRC()"/>
                    <span>TESTING</span>
                </button>

                <p:remoteCommand name="testpageRC" process="@this" update="montest" action="#{ProviderLogin.TESTING()}"/>

                <p:commandButton styleClass="ZWButtonActionIntervention pfButtonOrange" value="#{GestionIntervention.m_typeNonTraitee}" action="#{ProviderLogin.TESTING()}"/>

            </h:form>

        </ui:define>    
    </ui:composition>

</h:body>

My java class (Bean)

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@SessionScoped
@ManagedBean(name="ProviderLogin")
public class ProviderLogin implements Serializable
{ 
    private int i;

    public int getI(){return i;}

    public void TESTING(){i++;}
}

I have a breakpoint in the function 'TESTING()'

When I press the 'p:commandButton', the breakpoint is reached

When I press the 'button' (p:remoteCommand is called), the breakpoint is NOT reached

What is really strange, is that the 'p:remoteCommand' works for this: update="montest" But, the method in the bean is not fired.

By the way, when I start to write #{... I have access to my bean (variable and methods)

I use Primefaces 6.2


Solution

  • Problem found.

    Every web pages defines the content of a template. In this template there is the section "content" that cointained 2 <h:form>. One is renderer when the user is not logged. The other one is rendered when the user is logged correctly.

    In each page that re-define the content (when user is logged), i had a second section of <h:form>. It seems that action of the <p:remoteCommand> doesn't manage this well while <p:button> does. I just deleted that form on each pages and my problem was solved.

    My template (content part)

    <div id="content" style="padding: 10px">
        <h:form rendered="#{!ProviderLogin.m_User.m_bLogged}">
            <h:button value="Connexion" outcome="/Gestion/Connexion.xhtml"/>
        </h:form>
        <h:form id="formContent" rendered="#{ProviderLogin.m_User.m_bLogged}">
            <ui:insert name="content" >
                <ui:include src="content.xhtml" />
            </ui:insert>
        </h:form>
    </div>
    

    One page that re-define the content part (with 2nd form that gave me errors)

    <h:body>
        <ui:composition template="../Template/template.xhtml">
            <ui:define name="content">
                <h:form id="formInterventions">
                    PAGE CONTENT
                </h:form>
            </ui:define>    
        </ui:composition>
    </h:body>
    

    The same page that re-define the content part (without 2nd form) then, my action of the <p:remoteCommand> works !

     <h:body>
         <ui:composition template="../Template/template.xhtml">
             <ui:define name="content">
                 PAGE CONTENT
             </ui:define>   
         </ui:composition>
     </h:body>
    

    I also give you this informations :

    i use update of some controls like this showcase :

    https://www.primefaces.org/showcase/ui/ajax/poll.xhtml

    You need to give the id of the control you want to update

    When you are using <h:form>, sometimes you need to also specify the id of the form like this :

    update="formID:controlID"
    

    Because of that <h:form> defined in my template (which i forgot), it wasn't working because i didn't expect that at all and i didn't give that form an ID, so basically, a default id (j_idt27) was given.

    This means my update functionnality couldn't find the specified control id