5 Replies Latest reply: Jun 7, 2012 4:35 PM by vinod_t_krishnan RSS

    not able to call validator on drop down

    927837
      Hi,

      I want to call custom validator for Drop down. I have set autoSubmit= true and written validator as
      public void validateMethod(FacesContext facesContext,
      UIComponent uIComponent,
      Object object) {
      }

      in .jspx calling as validator="#{MyBean.validateMethod}" autoSubmit="true"

      when the validator will get called exactly?I have put sysout in the validator method but its not getting called. Please help regarding this.
        • 1. Re: not able to call validator on drop down
          Frank Nimphius-Oracle
          Hi,

          should be called during Process Validation phase. So when the value has been changed and the autosubmit fires. If your select choice component value property is bound to a managed bean in request scope, it wont be called because the managed bean value is reset for each request (which is a common mistake by the way) and thus nothing to validate.

          Maybe you want to provide more information like the JDeveloper version

          Frank
          • 2. Re: not able to call validator on drop down
            927837
            Hi Frank,

            Thanks for the reply.

            Actually I need to do a validation . Wherein if a checkbox is checked the drop down next to it should become required. If we uncheck the checkbox the dropdown should not be required and it should become disable.
            I am able to make drop down required conditionally. I check the checkbox and click on Save it gives me required EM for the Drop down. But when I deselect it it becomes disable but still now when i click on the Save button it gives the required EM. Also one thing, this is happening only when the EM is set for other fields also. i.e. when there are EM existing for other field also .

            <af:selectBooleanCheckbox label="Yes"
            binding="#{MyBean.myCheckBox}" value="#{MyBean.myCheckBoxSelected}" id="myChkID" autoSubmit="true" partialTriggers="mySoc1" valueChangeListener="#{MyBean.onMyChkBoxCheckUncheck}"></af:selectBooleanCheckbox>

            <af:selectOneChoice id="mySoc1" binding="#{MyBean.mySoc1}"
            value="#{MyBean.myMethodSelected}"
            partialTriggers="myChkID" required="#{MyBean.myCheckBoxSelected}"
            disabled="#{MyBean.myCheckBoxSelected eq false}"
            showRequired="false" requiredMessageDetail="Deselect checkbox or select option here.">
            <f:selectItems value="#{MyBean.myMethodList}"
            id="Si1"/>
            </af:selectOneChoice>




            the value change listner code

            if(this.getMyCheckBox().isSelected()==true || myCheckBoxSelected==true){
            this.getmySoc1().setDisabled(false);
            this.getmySoc1().setRequired(true);


            }else{
            this.getmySoc1().setRequired(false);
            this.getmySoc1().setDisabled(true);
            }


            The Jdev Version is 11g release 1 11.1.1.5.0 and JSF 2.0 . Please Help ASAP.Thanks in advance.
            • 3. Re: not able to call validator on drop down
              927837
              Hi,

              Can anyone please provide solution on this?
              • 4. Re: not able to call validator on drop down
                Deepansh Mathur
                Hi,

                You can try the following code as your value change listener

                public void changeListener(ValueChangeEvent valueChangeEvent) {
                this.mySoc1.setRequired((Boolean)valueChangeEvent.getNewValue());
                }


                <af:selectBooleanCheckbox label="Yes"
                binding="#{MyBean.myCheckBox}" value="#{pageFlowScope.valueOfYes}" id="myChkID" autoSubmit="true" valueChangeListener="#{MyBean.onMyChkBoxCheckUncheck}"></af:selectBooleanCheckbox>

                <af:selectOneChoice id="mySoc1" binding="#{MyBean.mySoc1}"
                value="#{MyBean.myMethodSelected}"
                requiredMessageDetail="Deselect checkbox or select option here.">
                <f:selectItems value="#{MyBean.myMethodList}"
                id="Si1"/>
                </af:selectOneChoice>

                This should work.

                Deepansh Mathur
                • 5. Re: not able to call validator on drop down
                  vinod_t_krishnan
                  if you are expecting a red border for the selectonechoice.. then use the following code to achieve that.
                  //your working code where u r setting required to true
                  getmysoc1().setValid(false);
                  The code provided by Depansh is more simple with the logic.. you may try that as well..