0

I am having some trouble getting a p:remoteCommand to work, it is defined as follows:

<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    template="/template.xhtml" xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">
    <ui:define name="content">
        <h:form id="form" enctype="multipart/form-data" >
            <p:remoteCommand name="connectionTest" action="#{entry.checkConnection}" oncomplete="console.log('BAR');" style="display: none;"/> 
                            
            <p:inputText id="dummy" required="true" value="#{entry.X}" disabled="#{entry.disabled}" />           
            
            <script type="text/javascript"> 
                $(function() {
                    $(document).ready(async function () {
                        console.log('foo');
                        connectionTest();
                    });
                });
            </script>
        </h:form>
    </ui:define>
</ui:composition>

And a bean method in a ViewScoped bean named "entry":

public void checkConnection() {
    ...do stuff
}

The remote command is invoked, as foo and BAR are printed to the console, but the actual bean method checkConnection is not being invoked. I have tried all permutations of action vs actionListener and entry.checkConnection vs entry.checkConnection().

The remoteCommand and script tags are in the same h:form inside a ui:define inside a ui:composition. What am I missing?

Edit: after some trial and error, it seems related to having a required="true" p:inputText on the same form. I have updated my question accordingly. Moving the p:remoteCommand out of the form seems to make it work, but I still am unsure why a p:remoteCommand inside a form with a required p:inputText does not work.

Gumpf
  • 197
  • 7
  • Please provide a [mcve]. For example, is the remote command in a form? See also https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Jasper de Vries Mar 30 '22 at 14:10
  • 1
    In your case the remote command process all the form, so if the required field is empty, the action isn't invoked, check the question linked by Jasper de Vries for more info. Add process="@this" if you don't need to process anything. – WoAiNii Apr 01 '22 at 21:01

0 Answers0