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 :
Property Names - Property names, such as name and
Methods calls - Method calls, such as the hashcode(),
which returns hash code of current object.
Array Indices - For example, array, which returns
first element of current object.
The name is the property of the initial or root object. This root object
provided to the OGNL through the OGNL context.
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.
It then gets the numericValue property from that
Finally the String is returned after calling the
toString() on resulting Integer object.