Tuesday, August 23, 2011

UNSAVED DATA WARNING


Introduction :

If You are working on a form or table and some of data is modified or added, on moving to other page of taskflow this data will remain in cache or it will show no warning for unsaved data


How to do it :

To show warning of unsaved data between page navigation just go to property of af:document and set Uncommitted data warning to true. Then whenever you move out of that page or close the browser it will show you a warning of unsaved data. 

Warning message
Warning Message

SHOW UNSAVED ROW HIGHLIGHTED


Introduction :
This post to describe how to show a unsaved row of a table. There is a property of an entity which is entity state. This entity can be in 4 states:
  1. New
  2. Modified
  3. Unmodified
  4. Initialized

How to do it :
just copy the following code and paste in to inline style of column of table. This will highlight newly created row.

#{row.row.entities[0].entityState == 0? 'background-color:#ff9c31;':''}

To highlight modified row compare entity state to 2

0 for new unsaved row
1 for unmodified row
2 for modified unsaved row
-1 for initialized row

for showing unsaved rows whether modified or a new place both condition together. 

#{row.row.entities[0].entityState == 2||row.row.entities[0].entityState == 0?'background-color:#ff9c31;':''}




Thursday, August 4, 2011

CUSTOM VALIDATOR


In my last post I included information about different validations available in ADF-BC. These validations are very easy to apply in Entity object and view objects. There are most of the possible validations are available. Still you may want to define your own custom validation, for this you will write code in your managed bean. 
To apply a custom validator go to your jspx or jsff page and select the input text or other input component an go to its properties. Give a function name to validator.

 
This validator will look like :
public void NameValidation(FacesContext facesContext, UIComponent uIComponent, Object object) {

return true:

}


Now in this validator method you can write your own validation code. Such as I have written here validation of name input text, so that user can only insert capital letters, numbers and “_”. If validation fails it will show a error, else nothing.
public void NameValidation(FacesContext facesContext, UIComponent uIComponent, Object object) {
        String value = (String)object;
        if ((value == null) || value.length() == 0) {
            return;
        }
        String expression = "^[A-Z 0-9_]{2,100}$";
        CharSequence inputStr = value;
        Pattern pattern = Pattern.compile(expression);
        Matcher matcher = pattern.matcher(inputStr);
        String error = “Only upper case letter and _ allowd”;
        if (matcher.matches()) {
        } 
else {
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, error, null));
        }
    }

When you run application and validation fails you will get an error like this:

Monday, August 1, 2011

ADF-BC Validations


This framework provides very good feature of validation. In ADF we can validate user inputs at different levels. Which are
  • Attribute level: Fires on value change.
  • Entity level: Fires on moving from one record to another.
  • Transaction level: Fires after attribute and entity level validations are complete. It validates Master-detail validations.
These validations are defined in Entity object and View object level. There are many rules of possible validations and ADF-BC provide lots of them. These validations rules are:
  • Compare: Attribute value compared with other attribute's value or an expression or a literal.
  • List: Value is validated against a list of values.
  • Key Exists: Its like a foreign key validator, it checks the value whether it exists or not. Like value for employee will check for the department to check whether it is present or not.
  • Regular Expressions: Value compared against provided regular expression. Like for email validation, Number Format validation.
  • Script Expression: Groovy expression are used to do validations.
  • Method Validator: When a method validator is created it adds a method in corresponding entityImpl calss. Like
public boolean validateEname(String ename) {  
return true;
}