Validation of a b:modal form is not working



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am trying to validate a modal form ( JSF/Bootsfaces ) and prevent it from being saved if the inputtext is not correct. For some reason I ignore it is not working, here is the JSF code:



 <b:modal id="creation"
title="#msgs['page.manageFlights.addingNew']"
styleClass="formValidationModalClass"
closeOnEscape="false"
backdrop="false"
closable="false">

<b:form id="createModal">
<b:selectOneMenu
value="#flightBean.currentFlight.journey"
label="#msgs['page.manageFlights.findAllJourneys']"
required="true"
requiredMessage="Please select a journey"
large-screen="full-width">
<f:selectItems value="#journeyBean.findAllJourneys()" var="journey" itemValue="#journey" itemLabel="#journey.departureLocation -> #journey.arrivalLocation" />

</b:selectOneMenu>
<b:dateTimePicker
value="#flightBean.currentFlight.departureDate"
label="#msgs['page.manageFlights.departureDate']"
required="true"
requiredMessage="Please enter a date and time"
large-screen="full-width">
</b:dateTimePicker>

<b:dateTimePicker
value="#flightBean.currentFlight.arrivalDate"
label="#msgs['page.manageFlights.arrivalDate']"
required="true"
requiredMessage="Please enter a date and time"
large-screen="full-width">
</b:dateTimePicker>

<b:inputText value="#flightBean.currentFlight.numberOfBusinessClassSeats"
label="#msgs['page.manageFlights.numberOfBusinessClassSeats']"
required="true"
requiredMessage="The number of seats must be positive"
large-screen="full-width">
<f:validateLongRange minimum = "1" maximum = "2000" />
</b:inputText>
<b:inputText
value="#flightBean.currentFlight.numberOfEconomyClassSeats"
label="#msgs['page.manageFlights.numberOfEconomyClassSeats']"
required="true"
requiredMessage="Please enter a number"
validatorMessage="The number of seats must be positive"
large-screen="full-width">
</b:inputText>
<br/>
<b:row>
<b:column>
<b:commandButton
largeScreen="half"
value="#msgs['cancel.button']"
dismiss="modal"
action="#flightBean.resetCurrentFlight()"
oncomplete="$('#creation').modal('hide')"
/>
<b:commandButton
largeScreen="half"
dismiss="modal"
update="@(#dataTable)"
value="#msgs['save.button']" look="success"
action="#flightBean.addFlight(flightBean.currentFlight)"
oncomplete="if(!validationFailed) $('#creation').modal('hide');">
</b:commandButton>
</b:column>
</b:row>
<b:fetchBeanInfos/>
<b:messages/>
</b:form>
</b:modal>


I am trying to check if the number of business class seats is positive.
As you can see I added fetchbeaninfos, validateLongRange and oncomplete.










share|improve this question






























    1















    I am trying to validate a modal form ( JSF/Bootsfaces ) and prevent it from being saved if the inputtext is not correct. For some reason I ignore it is not working, here is the JSF code:



     <b:modal id="creation"
    title="#msgs['page.manageFlights.addingNew']"
    styleClass="formValidationModalClass"
    closeOnEscape="false"
    backdrop="false"
    closable="false">

    <b:form id="createModal">
    <b:selectOneMenu
    value="#flightBean.currentFlight.journey"
    label="#msgs['page.manageFlights.findAllJourneys']"
    required="true"
    requiredMessage="Please select a journey"
    large-screen="full-width">
    <f:selectItems value="#journeyBean.findAllJourneys()" var="journey" itemValue="#journey" itemLabel="#journey.departureLocation -> #journey.arrivalLocation" />

    </b:selectOneMenu>
    <b:dateTimePicker
    value="#flightBean.currentFlight.departureDate"
    label="#msgs['page.manageFlights.departureDate']"
    required="true"
    requiredMessage="Please enter a date and time"
    large-screen="full-width">
    </b:dateTimePicker>

    <b:dateTimePicker
    value="#flightBean.currentFlight.arrivalDate"
    label="#msgs['page.manageFlights.arrivalDate']"
    required="true"
    requiredMessage="Please enter a date and time"
    large-screen="full-width">
    </b:dateTimePicker>

    <b:inputText value="#flightBean.currentFlight.numberOfBusinessClassSeats"
    label="#msgs['page.manageFlights.numberOfBusinessClassSeats']"
    required="true"
    requiredMessage="The number of seats must be positive"
    large-screen="full-width">
    <f:validateLongRange minimum = "1" maximum = "2000" />
    </b:inputText>
    <b:inputText
    value="#flightBean.currentFlight.numberOfEconomyClassSeats"
    label="#msgs['page.manageFlights.numberOfEconomyClassSeats']"
    required="true"
    requiredMessage="Please enter a number"
    validatorMessage="The number of seats must be positive"
    large-screen="full-width">
    </b:inputText>
    <br/>
    <b:row>
    <b:column>
    <b:commandButton
    largeScreen="half"
    value="#msgs['cancel.button']"
    dismiss="modal"
    action="#flightBean.resetCurrentFlight()"
    oncomplete="$('#creation').modal('hide')"
    />
    <b:commandButton
    largeScreen="half"
    dismiss="modal"
    update="@(#dataTable)"
    value="#msgs['save.button']" look="success"
    action="#flightBean.addFlight(flightBean.currentFlight)"
    oncomplete="if(!validationFailed) $('#creation').modal('hide');">
    </b:commandButton>
    </b:column>
    </b:row>
    <b:fetchBeanInfos/>
    <b:messages/>
    </b:form>
    </b:modal>


    I am trying to check if the number of business class seats is positive.
    As you can see I added fetchbeaninfos, validateLongRange and oncomplete.










    share|improve this question


























      1












      1








      1








      I am trying to validate a modal form ( JSF/Bootsfaces ) and prevent it from being saved if the inputtext is not correct. For some reason I ignore it is not working, here is the JSF code:



       <b:modal id="creation"
      title="#msgs['page.manageFlights.addingNew']"
      styleClass="formValidationModalClass"
      closeOnEscape="false"
      backdrop="false"
      closable="false">

      <b:form id="createModal">
      <b:selectOneMenu
      value="#flightBean.currentFlight.journey"
      label="#msgs['page.manageFlights.findAllJourneys']"
      required="true"
      requiredMessage="Please select a journey"
      large-screen="full-width">
      <f:selectItems value="#journeyBean.findAllJourneys()" var="journey" itemValue="#journey" itemLabel="#journey.departureLocation -> #journey.arrivalLocation" />

      </b:selectOneMenu>
      <b:dateTimePicker
      value="#flightBean.currentFlight.departureDate"
      label="#msgs['page.manageFlights.departureDate']"
      required="true"
      requiredMessage="Please enter a date and time"
      large-screen="full-width">
      </b:dateTimePicker>

      <b:dateTimePicker
      value="#flightBean.currentFlight.arrivalDate"
      label="#msgs['page.manageFlights.arrivalDate']"
      required="true"
      requiredMessage="Please enter a date and time"
      large-screen="full-width">
      </b:dateTimePicker>

      <b:inputText value="#flightBean.currentFlight.numberOfBusinessClassSeats"
      label="#msgs['page.manageFlights.numberOfBusinessClassSeats']"
      required="true"
      requiredMessage="The number of seats must be positive"
      large-screen="full-width">
      <f:validateLongRange minimum = "1" maximum = "2000" />
      </b:inputText>
      <b:inputText
      value="#flightBean.currentFlight.numberOfEconomyClassSeats"
      label="#msgs['page.manageFlights.numberOfEconomyClassSeats']"
      required="true"
      requiredMessage="Please enter a number"
      validatorMessage="The number of seats must be positive"
      large-screen="full-width">
      </b:inputText>
      <br/>
      <b:row>
      <b:column>
      <b:commandButton
      largeScreen="half"
      value="#msgs['cancel.button']"
      dismiss="modal"
      action="#flightBean.resetCurrentFlight()"
      oncomplete="$('#creation').modal('hide')"
      />
      <b:commandButton
      largeScreen="half"
      dismiss="modal"
      update="@(#dataTable)"
      value="#msgs['save.button']" look="success"
      action="#flightBean.addFlight(flightBean.currentFlight)"
      oncomplete="if(!validationFailed) $('#creation').modal('hide');">
      </b:commandButton>
      </b:column>
      </b:row>
      <b:fetchBeanInfos/>
      <b:messages/>
      </b:form>
      </b:modal>


      I am trying to check if the number of business class seats is positive.
      As you can see I added fetchbeaninfos, validateLongRange and oncomplete.










      share|improve this question
















      I am trying to validate a modal form ( JSF/Bootsfaces ) and prevent it from being saved if the inputtext is not correct. For some reason I ignore it is not working, here is the JSF code:



       <b:modal id="creation"
      title="#msgs['page.manageFlights.addingNew']"
      styleClass="formValidationModalClass"
      closeOnEscape="false"
      backdrop="false"
      closable="false">

      <b:form id="createModal">
      <b:selectOneMenu
      value="#flightBean.currentFlight.journey"
      label="#msgs['page.manageFlights.findAllJourneys']"
      required="true"
      requiredMessage="Please select a journey"
      large-screen="full-width">
      <f:selectItems value="#journeyBean.findAllJourneys()" var="journey" itemValue="#journey" itemLabel="#journey.departureLocation -> #journey.arrivalLocation" />

      </b:selectOneMenu>
      <b:dateTimePicker
      value="#flightBean.currentFlight.departureDate"
      label="#msgs['page.manageFlights.departureDate']"
      required="true"
      requiredMessage="Please enter a date and time"
      large-screen="full-width">
      </b:dateTimePicker>

      <b:dateTimePicker
      value="#flightBean.currentFlight.arrivalDate"
      label="#msgs['page.manageFlights.arrivalDate']"
      required="true"
      requiredMessage="Please enter a date and time"
      large-screen="full-width">
      </b:dateTimePicker>

      <b:inputText value="#flightBean.currentFlight.numberOfBusinessClassSeats"
      label="#msgs['page.manageFlights.numberOfBusinessClassSeats']"
      required="true"
      requiredMessage="The number of seats must be positive"
      large-screen="full-width">
      <f:validateLongRange minimum = "1" maximum = "2000" />
      </b:inputText>
      <b:inputText
      value="#flightBean.currentFlight.numberOfEconomyClassSeats"
      label="#msgs['page.manageFlights.numberOfEconomyClassSeats']"
      required="true"
      requiredMessage="Please enter a number"
      validatorMessage="The number of seats must be positive"
      large-screen="full-width">
      </b:inputText>
      <br/>
      <b:row>
      <b:column>
      <b:commandButton
      largeScreen="half"
      value="#msgs['cancel.button']"
      dismiss="modal"
      action="#flightBean.resetCurrentFlight()"
      oncomplete="$('#creation').modal('hide')"
      />
      <b:commandButton
      largeScreen="half"
      dismiss="modal"
      update="@(#dataTable)"
      value="#msgs['save.button']" look="success"
      action="#flightBean.addFlight(flightBean.currentFlight)"
      oncomplete="if(!validationFailed) $('#creation').modal('hide');">
      </b:commandButton>
      </b:column>
      </b:row>
      <b:fetchBeanInfos/>
      <b:messages/>
      </b:form>
      </b:modal>


      I am trying to check if the number of business class seats is positive.
      As you can see I added fetchbeaninfos, validateLongRange and oncomplete.







      jsf bootsfaces






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 15:42









      Jasper de Vries

      9,08653574




      9,08653574










      asked Nov 15 '18 at 15:06









      Ayoub RossiAyoub Rossi

      6510




      6510






















          1 Answer
          1






          active

          oldest

          votes


















          1














          <b:fetchBeanInfos> and validationFailed only work after an AJAX request. You need to send the input to the server, have it validated there, and only when the response is sent back to the client, validationFailed is updated.



          My suggestion is to use simple JavaScript to show the error message and to disable the button.



          However, if you prefer to use server-side validation, here's what to do:



          • Add an empty validateInput() method to your bean. It doesn't need any implementation; it just has to be there so it can be called by an JSF AJAX call.

          • Add an id to <b:fetchBeanInfos>.


          • Add an AJAX change listener to each input field. Depending on the type of the input field, you may need a different listener (onblur, onchange, etc.), but the general idea is like so:



            <b:inputText
            onblur="ajax:flightBean.validateInput()"
            update="**:fetchBeansId"
            value="..."
            label="..."
            required="true"
            requiredMessage="..."
            validatorMessage="...">
            </b:inputText>
            <b:fetchBeanInfos id="fetchBeansId"/>


          The **:idbit helps you if your JSF page has multiple "namespaces", such as forms, modals, data tables, and tabs. These namespaces add a prefix to the id, and **:id allows you to find the id no matter what the prefix is.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322359%2fvalidation-of-a-bmodal-form-is-not-working%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            <b:fetchBeanInfos> and validationFailed only work after an AJAX request. You need to send the input to the server, have it validated there, and only when the response is sent back to the client, validationFailed is updated.



            My suggestion is to use simple JavaScript to show the error message and to disable the button.



            However, if you prefer to use server-side validation, here's what to do:



            • Add an empty validateInput() method to your bean. It doesn't need any implementation; it just has to be there so it can be called by an JSF AJAX call.

            • Add an id to <b:fetchBeanInfos>.


            • Add an AJAX change listener to each input field. Depending on the type of the input field, you may need a different listener (onblur, onchange, etc.), but the general idea is like so:



              <b:inputText
              onblur="ajax:flightBean.validateInput()"
              update="**:fetchBeansId"
              value="..."
              label="..."
              required="true"
              requiredMessage="..."
              validatorMessage="...">
              </b:inputText>
              <b:fetchBeanInfos id="fetchBeansId"/>


            The **:idbit helps you if your JSF page has multiple "namespaces", such as forms, modals, data tables, and tabs. These namespaces add a prefix to the id, and **:id allows you to find the id no matter what the prefix is.






            share|improve this answer



























              1














              <b:fetchBeanInfos> and validationFailed only work after an AJAX request. You need to send the input to the server, have it validated there, and only when the response is sent back to the client, validationFailed is updated.



              My suggestion is to use simple JavaScript to show the error message and to disable the button.



              However, if you prefer to use server-side validation, here's what to do:



              • Add an empty validateInput() method to your bean. It doesn't need any implementation; it just has to be there so it can be called by an JSF AJAX call.

              • Add an id to <b:fetchBeanInfos>.


              • Add an AJAX change listener to each input field. Depending on the type of the input field, you may need a different listener (onblur, onchange, etc.), but the general idea is like so:



                <b:inputText
                onblur="ajax:flightBean.validateInput()"
                update="**:fetchBeansId"
                value="..."
                label="..."
                required="true"
                requiredMessage="..."
                validatorMessage="...">
                </b:inputText>
                <b:fetchBeanInfos id="fetchBeansId"/>


              The **:idbit helps you if your JSF page has multiple "namespaces", such as forms, modals, data tables, and tabs. These namespaces add a prefix to the id, and **:id allows you to find the id no matter what the prefix is.






              share|improve this answer

























                1












                1








                1







                <b:fetchBeanInfos> and validationFailed only work after an AJAX request. You need to send the input to the server, have it validated there, and only when the response is sent back to the client, validationFailed is updated.



                My suggestion is to use simple JavaScript to show the error message and to disable the button.



                However, if you prefer to use server-side validation, here's what to do:



                • Add an empty validateInput() method to your bean. It doesn't need any implementation; it just has to be there so it can be called by an JSF AJAX call.

                • Add an id to <b:fetchBeanInfos>.


                • Add an AJAX change listener to each input field. Depending on the type of the input field, you may need a different listener (onblur, onchange, etc.), but the general idea is like so:



                  <b:inputText
                  onblur="ajax:flightBean.validateInput()"
                  update="**:fetchBeansId"
                  value="..."
                  label="..."
                  required="true"
                  requiredMessage="..."
                  validatorMessage="...">
                  </b:inputText>
                  <b:fetchBeanInfos id="fetchBeansId"/>


                The **:idbit helps you if your JSF page has multiple "namespaces", such as forms, modals, data tables, and tabs. These namespaces add a prefix to the id, and **:id allows you to find the id no matter what the prefix is.






                share|improve this answer













                <b:fetchBeanInfos> and validationFailed only work after an AJAX request. You need to send the input to the server, have it validated there, and only when the response is sent back to the client, validationFailed is updated.



                My suggestion is to use simple JavaScript to show the error message and to disable the button.



                However, if you prefer to use server-side validation, here's what to do:



                • Add an empty validateInput() method to your bean. It doesn't need any implementation; it just has to be there so it can be called by an JSF AJAX call.

                • Add an id to <b:fetchBeanInfos>.


                • Add an AJAX change listener to each input field. Depending on the type of the input field, you may need a different listener (onblur, onchange, etc.), but the general idea is like so:



                  <b:inputText
                  onblur="ajax:flightBean.validateInput()"
                  update="**:fetchBeansId"
                  value="..."
                  label="..."
                  required="true"
                  requiredMessage="..."
                  validatorMessage="...">
                  </b:inputText>
                  <b:fetchBeanInfos id="fetchBeansId"/>


                The **:idbit helps you if your JSF page has multiple "namespaces", such as forms, modals, data tables, and tabs. These namespaces add a prefix to the id, and **:id allows you to find the id no matter what the prefix is.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 8 '18 at 19:37









                Stephan RauhStephan Rauh

                2,13511128




                2,13511128





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53322359%2fvalidation-of-a-bmodal-form-is-not-working%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Use pre created SQLite database for Android project in kotlin

                    Darth Vader #20

                    Ondo