How to display a dependent list box disabled if no child data exist

A requirement on OTN was to disable the dependent list box of a model driven list of value configuration whenever the list is empty.

To disable the dependent list, the af:selectOneChoice component needs to be refreshed with every value change of the parent list, which however already is the case as the list boxes are already dependent.

When you create model driven list of values as choice lists in an ADF Faces page, two ADF list bindings are implicitly created in the PageDef file of the page that hosts the input form.

At runtime, a list binding is an instance of FacesCtrlListBinding, which exposes getItems() as a method to access a list of available child data (java.util.List). Using Expression Language, the list is accessible with

#{bindings.list_attribute_name.items}

To dynamically set the disabled property on the dependent af:selectOneChoice component, however, you need a managed bean that exposes the following two methods

//empty – but required – setter method
public void setIsEmpty(boolean isEmpty) {}

//the method that returns true/false when the list is empty or
//has values
public boolean isIsEmpty() {
  FacesContext fctx = FacesContext.getCurrentInstance();
  ELContext elctx = fctx.getELContext();
  ExpressionFactory exprFactory =   
                      fctx.getApplication().getExpressionFactory();
  ValueExpression vexpr =
                      exprFactory.createValueExpression(elctx,  
                      "#{bindings.EmployeeId.items}",
                      Object.class);
  List employeesList = (List) vexpr.getValue(elctx);                     
  return employeesList.isEmpty()? true : false;     
}

If referenced from the dependent choice list, as shown below, the list is disabled whenever it contains no list data
<! --  master list -->
<af:selectOneChoice value="#{bindings.DepartmentId.inputValue}"
                                 label="#{bindings.DepartmentId.label}"
                                 required="#{bindings.DepartmentId.hints.mandatory}"
                                  shortDesc="#{bindings.DepartmentId.hints.tooltip}"
                                  id="soc1" autoSubmit="true">
     <f:selectItems value="#{bindings.DepartmentId.items}" id="si1"/>
</af:selectOneChoice>

<! --  dependent  list -->

<af:selectOneChoice value="#{bindings.EmployeeId.inputValue}"
                                  label="#{bindings.EmployeeId.label}"   
                                  required="#{bindings.EmployeeId.hints.mandatory}"
                                  shortDesc="#{bindings.EmployeeId.hints.tooltip}"
                                  id="soc2" disabled="#{lovTestbean.isEmpty}"
                                  partialTriggers="soc1">
    <f:selectItems value="#{bindings.EmployeeId.items}" id="si2"/>
</af:selectOneChoice>

Comments:

Post a Comment:
Comments are closed for this entry.
About

The Oracle JDeveloper forum ranks in the Top 5 of the most active forums on the Oracle Technology Network (OTN).



The OTN Harvest blog is a summary of selected topics posted on the OTN Oracle JDeveloper forum.



It is an effort to turn knowledge exchange into an interesting read for developers who enjoy little nuggets of wisdom





Frank Nimphius

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today