How to make some LOV items non-selectable

Environment (JDeveloper 11.1.2.0.0,hr schema)

Lately we have a requirement to make some list of values (LOV) items non selectable. As an example suppose that the list of departments should show all departments but some of them mus be disabled or non-selectable as shown below.

LOV with some items being disabled

In this post I will show how to build this kind of LOVs. This example is based on hr schema, mainly on EMPLOYEES and DEPARTMENTS table.  Our goal is to create LOV for the DepartmentId attribute in Employees view but the departments: Administration, Marketing, Purchasing, and Human Resources should be disabled and non selectable.  I will assume that you have already built the business component for this example. The implemantation steps are:

  1. Right click on your page and select Go to page Definition from the menu.
  2. If the page definition file opens in the source view, select the Overview tab at the bottom of the editor. and click the green plus icon  to create a control binding as shown below.create control binding
  3. After click the green plus icon the Insert Item window will be shown, select the tree item and click OK.

    select tree binding from insert item window

  4. After you select the tree binding, the Create Tree Binding window will be shown. Click the Add button to create a new Root Data Source reference or select from a list of existing iterators.The root data source provides the list data and should point to a View Object that you created for the data lookup. Don’t use any View Object that you use for data input within your application. In our case I select DepartmentsView1 to be the root data source.

    select root data source from the data controls

  5. Still the Create Tree Binding window opened, click add rule (green plus icon) and choose the AddRule menu option. This creates a rule entry for the top-level View Object of the selected root data source.

    add rule menu option

  6. Still also in the Create Tree Binding window, move both DepartmentId and DepartmentName to the Display attribute area. we need the DepartmentId for the list value and the DepartmentName to be the display value.

    select display attributes

  7. Now return back to the page and open it it the Jdeveloper visual editor.
  8. From the data controls panel, drag and drop the departmentId attribute from the EmployeesView1 as selectOneChoice component. Press OK and do not do any configuration. Note that Jdeveloper shows an error message Indicates that a list data source is not selected, so we are enforced to select a data source and we will delete it later.

    Edit lis binding window

  9. Now the page source for the DepartmentId attribute will be something like this:
    <af:selectOneChoice value="#{bindings.DepartmentId.inputValue}" label="#{bindings.DepartmentId.label}"
    required="#{bindings.DepartmentId.hints.mandatory}"
    shortDesc="#{bindings.DepartmentId.hints.tooltip}" id="soc1">
    <f:selectItems value="#{bindings.DepartmentId.items}" id="si1"/>
    </af:selectOneChoice>
  10. Delete <f:selectItems> tag  inside <af:selectOneChoice> tag. The page source for the DepartmentId attribute should be:
    <af:selectOneChoice value="#{bindings.DepartmentId.inputValue}" label="#{bindings.DepartmentId.label}"
    required="#{bindings.DepartmentId.hints.mandatory}"
    shortDesc="#{bindings.DepartmentId.hints.tooltip}" id="soc1"/>

    You can also delete the f:selectItems child component from the structure window.

  11. From the structure window, select the af:selectOneChoice and Insert inside af:selectOneChoice |ADF Faces | For Each from the right mouse context menu as shown below.

    insert foreach component

  12. Select the af:forEach component and open the Property Inspector. Click the arrow icon next to the Items property and select the tree binding rangeSet method entry.The returned Expression Language expression should look like this: #{bindings.
    DepartmentsView1.rangeSet}. And set the var attribute to descriptive name. The Var property defines the name for the variable that at runtime is used to populate the list. In this example I chose list as a name.
  13. Now our DepartmentId attribute looks like:
     <af:selectOneChoice value="#{bindings.DepartmentId.inputValue}" label="#{bindings.DepartmentId.label}"
    required="#{bindings.DepartmentId.hints.mandatory}"
    shortDesc="#{bindings.DepartmentId.hints.tooltip}" id="soc1">
    <af:forEach items="#{bindings.DepartmentsView1.rangeSet}" var="list"/>
    </af:selectOneChoice>
  14. Select the af:forEach component in the Structure Window and choose Insert inside af:forEach | ADF Faces  and choose Select Item component as shown below.

    insert <af:selectItem> component

  15. For the af:selectItem component set the Value attribute to #{list.DepartmentId}, Label attribute to #{list.DepartmentName}, and Disabled attribute to #{list.DepartmentId eq 10 or list.DepartmentId eq 20 or list.DepartmentId eq 30 or list.DepartmentId eq 40} which represents the Ids of the departments we want to be disabled.
  16. With this configuration applied, the DepartmentId attribute look like this:
    <af:selectOneChoice value="#{bindings.DepartmentId.inputValue}" label="#{bindings.DepartmentId.label}"
    required="#{bindings.DepartmentId.hints.mandatory}"
    shortDesc="#{bindings.DepartmentId.hints.tooltip}" id="soc1">
    <af:forEach items="#{bindings.DepartmentsView1.rangeSet}" var="list">
    <af:selectItem label="#{list.DepartmentName}" id="si1" value="#{list.DepartmentId}"
    disabled="#{list.DepartmentId eq 10 or list.DepartmentId eq 20 or list.DepartmentId eq 30 or list.DepartmentId eq 40}"/>
    </af:forEach>
    </af:selectOneChoice>
  17. Run your page.

download the sample workspace:MakeSomeLOVItemsNonSelectable.rar

Please change the file extension to .zip or .rar after download.

 

Reference: Oracle Fusion Developer Guide Building Rich Internet Applications with Oracle ADF Business Components and Oracle ADF Faces. Frank Nimphius,Lynn Munsinger.

6 Comments

Filed under ADF

6 responses to “How to make some LOV items non-selectable

  1. Jai

    Hi,
    Is this solution efficient for pages implementing many (30-40 lovs) LOV attributes? What kind performance overload are we talking about implementing this solution versus normal lov implementation.

    Thanks
    Jai

    • Mohammad Jabr

      Hello Jai,
      Actually I did not test it from performance perspective for large LOV. And this method is used for a specific use case .
      I am not sure if you can achieve this functionality by using model driven LOV, but if you can do it with model driven LOV then it’s fine and you can share
      us with your solution.

      Regards

      • Jai

        Hello Mohammad,

        Thanks for your response. I appreciate it. Unfortunately, I do not have a solution but I wanted evaluate your solution to see if it fits my use case.

        My use case is simple and I thought it is a very common use case. 95% of our LOVs are lookup based and we have a enabled indicator in lookup table. If we design our lookup query with where clause enabled_ind=Y then it presents only valid lookup values in LOV but it is possible that over a period of time some lookups are disabled by user. Any record in main table with disabled lookup values will start showing blank description.

        Requirement is to still show description in read-only display and when user selects the record for modification then either only valid values appear in LOV or invalid values [enabled_ind=N] should be disabled.
        Do you have any recommendation for approaching a solution for this use case?
        We are using Jdev 11.1.1.6 and using model driven LOV. Since lookup presents static list for all users, we are planning to use Shared Application Module (Application Scope) implementation.

        Thanks,
        Jai

  2. frank

    It works on FireFox, but doesn’t work on IE. Do you know why?

    • Mohammad Jabr

      Hello Frank,
      Please check the Certification and Support Matrix for your Jdeveloper version.
      I have tested it in IE8 and it works fine.

Leave a reply to Mohammad Jabr Cancel reply