Category Archives: ADF

Oracle Application Development Framework

Retrieve the Old Value of an Attribute in the View Object

Sometimes we need to access the old value of an attribute, this is explained well by Chris Muir in ADF Insider video Retrieving the previous value of an ADF BC attribute. This can be done by using getPostedAttribute method in the EntityImpl class, this method gets the value originally read value for  a specific attribute from the database and it has a protected access modifier. But what if you want to access the old value in the View object and you don’t have a control on the Entity object; such as if the entity objects are deployed as ADF library jar and you don’t have any privilege to access or modify these entities; is it possible to access the old value from the view object? in this post I will show how do this in an easy way. Suppose we want to access the old value of the department name attribute in the DepartmentsView  which is based on Departments table in HR schema.

  1.  Create a transient attribute, OldDepartmentName in the DepartmentsView.
  2. Generate the DepartmentsViewRowImpl class, check the include accessors check box, this will add getter/setter methods for all the attributes of this view object. by default the getDepartmentName method will look like this: 
    /**
    * Gets the attribute value for the calculated attribute OldDepartmentName.
    * @return the OldDepartmentName
    */
    public String getOldDepartmentName() {
    return (String) getAttributeInternal(OLDDEPARTMENTNAME);
    }
  3. Override the getOldDepartmentName() method to:
        /**
         * Gets the attribute value for the calculated attribute OldDepartmentName.
         * @return the OldDepartmentName
         */
        public String getOldDepartmentName() {
            byte status = EntityImpl.STATUS_UNMODIFIED;
            return (String) getAttributeInternal(DEPARTMENTNAME, status);
        }

Now, the getOldDepartmentName() will return the old value from the database.

Leave a comment

Filed under ADF

Two Ways to Evaluate a Memory Scope Attribute Using Expression Language

All of us know how to evaluate a memory scope attribute using a dot notation syntax of the expression language.

Example: to access a request scope attribute, we use this syntax.

#{requestScope.attributeKey}

However, this syntax fails if the key has a dot (.) in its name. To overcome this limitation, expression language offers the string argument notation.

Example: to access a request scope attribute which has a (.) in its name, we use this syntax.

#{requestScope['attributeKey']}

 

1 Comment

Filed under ADF

How to Disable Specific Dates in af:inputDate Component

Environment (JDeveloper 11.1.2.3.0,ADF Faces)

The inputDate component creates a text field for entering dates and (optionally) a glyph which opens a popup for picking dates from a calendar. However  in some cases we need to prevent the user from picking a specific days from the calender. In this post I will explain how to do this use case.

1- Create a simple JSF page and drag and drop af:inputDate component from the component palette into the newly created page.

2- Create a java class which implements org.apache.myfaces.trinidad.model.DateListProvider interface. This interface is used for providing a list of  individual dates within a given range.

3- Override the getDateList method, This method will generate a List of individual Date objects which will be rendered as disabled in a datePicker component.  An example is shown below.

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import javax.faces.context.FacesContext;

import org.apache.myfaces.trinidad.model.DateListProvider;

public class DaysBean
  implements DateListProvider
{
  public DaysBean()
  {
    super();
  }

  @Override
  public List getDateList(FacesContext facesContext, Calendar calendar, Date date, Date date2)
  {
    ArrayList disabledDates= new ArrayList();
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
    try
    {
      disabledDates.add(sdf.parse("01/01/2013"));
      disabledDates.add(sdf.parse("25/12/2013"));
    }
    catch (ParseException e)
    {
      e.printStackTrace();
      return Collections.emptyList();
    }
    return disabledDates;
  }
}

4-Register the Java Class as Managed Bean in adfc-config.xml file.

       Register Java Class as Managed Bean in adfc-config.xml file

5- Go to the JSF page and select the inputDate component, from the property inspector select the DisabledDays property and bind it to the manged bean defined in the previous step.

<af:document title="Test.jsf" id="d1">
<af:form id="f1">
<af:inputDate label="Date" id="id1" disabledDays="#{daysBean}"/>
</af:form>
</af:document>

Note:

 this binding requires periodic roundtrips. If you just want to disable certain weekdays (e.g. Saturday and Sunday), use the disabledDaysOfWeek attribute!

6- Run the page, and check that the date is disabled.

01/01/2013 is Disabled

Moreover, if the user enters the date manually without using the date picker, an error message will be shown to the user.

Error Message When the date is Entered Manually

download the sample application TestDisableDays.rar

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

Leave a comment

January 24, 2013 · 10:59 am

Application Development Framework Implementation specialist

Today, I took the Oracle Application Development Framework 11g Essentials exam (1Z0-554). Fortunately I passed it, and I am now an Application Development Framework Implementation specialist.

O_Certified Specialist_clr

4 Comments

Filed under ADF

How to Solve oracle.jbo.ConfigException: JBO-33001

Environment (JDeveloper, ADF BC, ADF Faces)

When you work with large application which contains more than one Model/one ViewController projects, you need to set the project dependency between the model and the view controller project., failing to do this you may face this exception.

oracle.jbo.ConfigException: JBO-33001: Configuration file /model/common/bc4j.xcfg is not found in the classpath.

To solve the problem, double click the viewController project to open project properties dialog, and select the the Dependencies node  and click the Edit Dependecies icon to add a dependency on the build output path or on one or more deployment archives.

Hope this will help someone faced the same problem.

3 Comments

Filed under ADF

Simple way to convert af:inputText to upperCase,lowerCase,capitalize

Environment (JDeveloper 11.1.2.2.0,ADF Faces)

Sometimes you need to force the user to enter upperCase or lowerCase or capitalize letters for input text component. fortunately, there is an easy way to do this by setting contentStyle of the input text.

  • To enforce the user to enter upperCase text use this style:
<af:inputText label="Label 1" id="it1" contentStyle="text-transform:uppercase;"/>
  • To enforce the user to enter lowerCase text use this style:
<af:inputText label="Label 1" id="it1" contentStyle="text-transform:lowercase;"/>
  • To enforce the user to enter capitalize (InitCap) text use this style:
<af:inputText label="Label 1" id="it1" contentStyle="text-transform:capitalize;"/>

5 Comments

Filed under ADF

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