OGNL Index
Posted on: January 22, 2011 at 12:00 AM
In this tutorial you will learn about the OGNL features

Introduction of OGNL in struts.

Object Graph Navigation Language is a expression language. It is used for getting and setting the properties of java object. It is very useful binding language for manipulating and retrieving different properties of java object. It has own syntax, which is very simple. It make code more readable. It acts as a binding language between GUI elements and model objects.

The Struts framework used a standard naming context for evaluating an OGNL expression. It sets OGNL context to be the ActionContext, and ValueStack to be the OGNL root object., The topmost object dealing with OGNL is a Map.

Syntax of OGNL :

Expression based on OGNL is very simple and easier to learn and use. The most commonly used unit in OGNL expression language is the navigation chain. The chain contain following parts :ADS_TO_REPLACE_1

  1. Property Names -  Property names, such  as name and text.
  2. Methods calls - Method calls, such as the hashcode(), which returns hash code of current object.
  3. Array Indices -  For example, array[0], which returns first element of current object.

For example.

name.toCharArray()[0].numericValue.toString()

Description :

  1. The name is the property of the initial or root object. This root object provided to the OGNL through the OGNL context.
  2. Then it calls the toCharArray() of the resulting string , After calling toCharArray() method, this first character at 0 index is extracted from the resulting array.
  3. It then gets the numericValue property from that character.
  4. Finally the String is returned after calling the toString() on resulting Integer object.

Example of OGNL :ADS_TO_REPLACE_2

  1. Access value of array using OGNL in struts2.
  2. How to access session value using OGNL.
  3. Access properties of bean from request object using OGNL.

Related Tags for OGNL Index:

Advertisements

Ads

 
Advertisement null

Ads