This discussion is archived
8 Replies Latest reply: Mar 22, 2012 3:44 AM by Pamela RSS

Disable selectOneChoice if af:inputText is required.

Pamela Newbie
Currently Being Moderated
Hello, My jdeveloper version is 11.1.2.1.0, web application session scope of the page.

I have a selectOneChoice for Department of employees that is linked with view link to employees form:

<af:selectOneChoice value="#{bindings.DepartmentView.inputValue}"
id="soc1" autoSubmit="true" inlineStyle="margin:10px 0 0 10px"
partialTriggers="t5">
<f:selectItems value="#{bindings.DepartmentView.items}" id="si1"/>
</af:selectOneChoice>

<af:inputText value="#{bindings.EmployeeView.inputValue}" requiredMessageDetail="Please enter employee Name" required="true" id="it7" />

(1) I add a new employee or I delete the name of the employee.
(2) I change the value of selectOneChoice to another departmentId
(3) I am getting the warning "Please enter employee Name" but when I enter it, it is no longer for the same Department.

How to make the selectOneChoice disabled until the value of the inputText is entered?
  • 1. Re: Disable selectOneChoice if af:inputText is required.
    Frank Nimphius Employee ACE
    Currently Being Moderated
    Hi,

    disable the select choice when you create a new employee (use the command button action listener). Then on teh input text field, have autosubmit=true set. In a value changelistener on the text field check that there is a value provided and enable the select one choice

    Frank
  • 2. Re: Disable selectOneChoice if af:inputText is required.
    Pamela Newbie
    Currently Being Moderated
    Thanks Frank, but I already did that before this post.
    The problem is that already existing employees are editable, so the user can delete the name of the employee and the select one choice is enabled while the current employee name is null.
    I wish I could make the select one choice disabled when the user deletes the name of the employee.
    public void employeeNameChangeListener(ValueChangeEvent valueChangeEvent) {
       if (valueChangeEvent.getNewValue() != null && valueChangeEvent.getNewValue().toString().length() > 0)  {
        //the value is not null I can enable the select one choice here.
       } else {
        //the value is null but I can't disable the select one choice here because the inputText field is required and it never gets into the value change listener. 
       }
    }
  • 3. Re: Disable selectOneChoice if af:inputText is required.
    John Stegeman Oracle ACE
    Currently Being Moderated
    One option you have is to mark the employee name field as not required in the JSF page, but leave it as required in the model. That way, you should make it into the value change listener.

    John
  • 4. Re: Disable selectOneChoice if af:inputText is required.
    prateekazam Journeyer
    Currently Being Moderated
    Hi ,

    First you have to change the order of execution of the code menas

    This is your code
    <af:selectOneChoice value="#{bindings.DepartmentView.inputValue}"
    id="soc1" autoSubmit="true" inlineStyle="margin:10px 0 0 10px"
    partialTriggers="t5">
    <f:selectItems value="#{bindings.DepartmentView.items}" id="si1"/>
    </af:selectOneChoice>
    
    <af:inputText value="#{bindings.EmployeeView.inputValue}" requiredMessageDetail="Please enter employee Name" required="true" id="it7" />
    Change the order like following
    <af:inputText value="#{bindings.EmployeeView.inputValue}" requiredMessageDetail="Please enter employee Name" required="true" id="it7" />
    <af:selectOneChoice value="#{bindings.DepartmentView.inputValue}"
    id="soc1" autoSubmit="true" inlineStyle="margin:10px 0 0 10px"
    partialTriggers="t5">
    <f:selectItems value="#{bindings.DepartmentView.items}" id="si1"/>
    </af:selectOneChoice>
    Step1:make by default disable true on select one choice.

    Step2:Bind the select one choice in backing means.example name (selectOneChoiceValue)

    Step3-Create the value change method on #{bindings.EmployeeView.inputValue} input
    public void inputValueChangeListener(ValueChangeListener value)
    {
       if(value.getValue==null)
       { 
         selectOneChoiceValue.setDisable(true);
         AdfFacesContext.getCurrentInstance().addPartialTraget(selectOneChoiceValue);
       }
       else
           {
               selectOneChoiceValue.setDisable(false);
              AdfFacesContext.getCurrentInstance().addPartialTraget(selectOneChoiceValue);
            }
    }
    Step 4.More inportance put autosubmit=true on input text

    May be this will help you

    Thanks
    Prateek
  • 5. Re: Disable selectOneChoice if af:inputText is required.
    Pamela Newbie
    Currently Being Moderated
    Thank you John. But your work around caused another problems. So I'll try to find another way.
    Thank you Prateek unfortunately I can't replace the order of my page. The employees are depending on a department and I add and edit employees per department.

    Edited by: 897833 on Mar 21, 2012 4:53 AM
  • 6. Re: Disable selectOneChoice if af:inputText is required.
    Pamela Newbie
    Currently Being Moderated
    What I did is binded the inputText to my bean and removed the required attribute from it in the JSF.
     
        public void employeeName(ValueChangeEvent valueChangeEvent) {
            if (valueChangeEvent.getNewValue() != null && valueChangeEvent.getNewValue().toString().length() > 0) {          
                this.departmentSelectOneChoice.setDisabled(false);
                AdfFacesContext.getCurrentInstance().addPartialTarget(departmentSelectOneChoice);            
                this.employeeNameInputText.setRequired(false);
            } else {            
                this.departmentSelectOneChoice.setDisabled(true);
                AdfFacesContext.getCurrentInstance().addPartialTarget(departmentSelectOneChoice);            
                this.employeeNameInputText.setRequired(true);         
            }
        }
    Also in the add new employee button action i added
      this.departmentSelectOneChoice.setDisabled(true);
                AdfFacesContext.getCurrentInstance().addPartialTarget(departmentSelectOneChoice);            
                this.employeeNameInputText.setRequired(true);
    And in the rollback button I added
      this.departmentSelectOneChoice.setDisabled(false);
                AdfFacesContext.getCurrentInstance().addPartialTarget(departmentSelectOneChoice);            
      this.employeeNameInputText.setRequired(false);
    Edited by: 897833 on Mar 22, 2012 3:20 AM
  • 7. Re: Disable selectOneChoice if af:inputText is required.
    John Stegeman Oracle ACE
    Currently Being Moderated
    ... which is essentially what I suggested :)
  • 8. Re: Disable selectOneChoice if af:inputText is required.
    Pamela Newbie
    Currently Being Moderated
    Actually I had to remove the required from the model, because when I am trying to delete an employee that has null value for a name I can't do it because of the following error:
    Adding the following JSF error message: Attribute Name in AppModule.EmployeeView is required.
    oracle.jbo.AttrValException: JBO-27014: Attribute Name in AppModule.EmployeeView is required.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points