A little help with Primefaces 6, using dynamic flag, checkbox, inputText and commandButtons

UI Components for JSF
Post Reply
nelikshadvio
Posts: 1
Joined: 16 Sep 2021, 05:14

16 Sep 2021, 05:17

I have implemented a module in xhtml with PrimeFaces 6, JSF and Java that a inputText is required and controlled mainly by a boolean flag, following a selectBooleanCheckbox and a commandButton (first is highly, second medium and third low priority).

The user story of the module is started as it follows:

If the main flag is true, the check is empty and inputText is false required. If the user decides to check it, then the inputText have the required to true, the validation is compulsory, and the commandButton have a true param to action this process. If not checked, simply click on the commandButton, with no validation of inputText - that is, I do not need validation property to check once I confirm .

If the main flag is false, the check is always marked and disabled, and the inputText always true, with the strong validation.

Here is the sample base (The right validation for a phone is 9 digits, and the user can be attended by phone or in-person, depends on inPersonControl --> true: can be in-person/phone, false: only by phone):

Code: Select all

<p:selectBooleanCheckbox
        itemLabel="Phone Reservation"
        value="#{confirmController.checked}"
        disabled="#{confirmController.disabledCheckbox and (not confirmController.inPersonControl)}"
        binding="#{checkbox}"
        rendered="#{confirmController.phoneAttentionPossibility}">              
    </p:selectBooleanCheckbox>

    <h:panelGroup id="pnlTelefono"
        rendered="#{confirmController.phoneAttentionPossibility}">
        <p:fieldset
                rendered="#{confirmController.phoneAttentionMode}">
            <p:outputLabel for="phoneSaved"
                value="Introduce your phone"/>
            <p:inputText id="phoneSaved" mask="999999999" type="tel"
                required="#{not confirmController.inPersonControl or (checkbox.value == 'true' and (param.phoneConfirm == 'true'))}" 
                value="#{confirmController.phoneSaved}"
                validator="#{confirmController.phoneValidator}"
                placeholder="Ej: 988677755">
            </p:inputText>
        </p:fieldset>
        <script type="text/javascript">
            
        </script>
    </h:panelGroup>

    <f:facet name="footer">

        <p:commandButton value="Back"
            action="#{confirmController.doGoSelectDate}"
            icon="ui-icon-back" inline="true" />

        <p:commandButton icon="ui-icon-accept"
            value="Aceptar"
            action="#{confirmController.doRegister}"
            process="phoneSaved"
            update="growl u/form:pnlExitDialogs" inline="true"                 
            ajax="false">
            <f:param name="phoneConfirm" value="#{checkbox.value == 'true' ? 'true' : 'false'}" />
        </p:commandButton>

        <p:commandButton value="Exit"t
            onclick="PF('dlgCancel').show();"
            icon="ui-icon-cancel" type="button" inline="true" />
    </f:facet>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests