Tuesday, 17 February 2015

How to make some LOV items non-selectable

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}, andDisabled 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.
Filed under ADF

How to pass parameters to an entry defined in the resource bundle

Environment (JDeveloper 11.1.2.0.0)
A validator’s error message can contain embedded expressions that are resolved by the server at runtime. This can be done easily in the model layer using named tokens delimited by curly braces as explained in  7.7.4 How to Embed a Groovy Expression in an Error Message section in developer guide. However, sometimes we need to pass a parameter to a string defined in resource bundle in the view layer. In this post I will show How to do it.
A resource bundle contains a number of named resources, where the data type of the named resources is String, and it is used to internationalize the application. I will assume that you have already defined your resource bundle and register it in the faces-config.xml as explained in Internationalizing and Localizing Pageschapter from web user interface guide.
Now suppose our resource bundle file contains this entry
#
MESSAGE=Hello {0}. You are watching {1}. Enjoy it.
you want to pass parameters  to the tokens delimited by curly braces, this can be done by using StringManger class as shown in the following method
public String PassParameterToBundle() {
// Add event code here...
String message=  oracle.jbo.common.StringManager.getString("view.ViewControllerBundleESSAGE", "No matching string found",new String[]{"ADF Developer","https://mjabr.wordpress.com/"});
System.out.println("messagemessage);
return message;
}
view.ViewControllerBundle in the method is the resource bundle that is registered in the faces-config.xml file as shown below
<?xml version="1.0" encoding="windows-1252"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee">
<application>
<default-render-kit-id>oracle.adf.rich</default-render-kit-id>
<resource-bundle>
<base-name>view.ViewControllerBundle</base-name>
<var>res</var>
</resource-bundle>
</application>
</faces-config>

No comments:

Post a Comment