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']}

 

Leave a comment

Filed under ADF

Create a Backing Bean for Existing Page

A backing bean is a special case of managed bean that has a one-to-one relationship to a single JSF page, and it exposes setter and getter methods for the components contained on the page. In Jdeveloper you can automatically expose UI components in a new bean when you create a new page by setting the Automatically Expose New UI Components in a New Managed Bean option as shown in the figure below.

Automatically Expose New UI Components in a New Managed Bean option

Automatically Expose New UI Components in a New Managed Bean option

But imagine you forget to set this option and later you decided to create a Backing Bean, do you need to explicitly bind each component to the backing bean?

Fortunately, you don’t need to bind the components manually, all you need is to open the page in the visual editor and  choose Design | Page Properties from the Jdeveloper menu bar as shown in the figure below:

Click on the page properties and then select the Component Binding tab from the page properties window, set the Auto Bind option, and create or select an existing managed bean.

expose3

2 Comments

Filed under Uncategorized

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

2012 in review

The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.

Here’s an excerpt:

4,329 films were submitted to the 2012 Cannes Film Festival. This blog had 50,000 views in 2012. If each view were a film, this blog would power 12 Film Festivals

Click here to see the complete report.

Leave a comment

Filed under Uncategorized

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