Overview
OGNL stands for Object Graph Navigation Language; it is an expression language for getting and setting properties of Java objects. You use the same expression for both getting and setting the value of a property.
The ognl.Ognl class contains convenience methods for evaluating OGNL expressions. You can do this in two stages, parsing an expression into an internal form and then using that internal form to either set or get the value of a property; or you can do it in a single stage, and get or set a property using the String form of the expression directly.
 |
As of OGNL version 2.7.x, expression can also be compiled (with the help of Javassist ) instead of being parsed. |
OGNL started out as a way to set up associations between UI components and controllers using property names. As the desire for more complicated associations grew, Drew Davidson created what he called KVCL, for Key-Value Coding Language, egged on by Luke Blanshard. Luke then reimplemented the language using ANTLR
, came up with the new name, and, egged on by Drew, filled it out to its current state. Later on Luke again reimplemented the language using JavaCC
. Further maintenance on all the code is done by Drew (with spiritual guidance from Luke). Until recently, OGNL is being maintained and enhance also by OpenSymphony
lead by Jesse with guidance from Drew and Luke.
We pronounce OGNL as a word, like the last syllables of a drunken pronunciation of "orthogonal."
Many people have asked exactly what OGNL is good for. Several of the uses to which OGNL has been applied are:
- A binding language between GUI elements (textfield, combobox, etc.) to model objects. Transformations are made easier by OGNL's TypeConverter mechanism to convert values from one type to another (String to numeric types, for example).
- A data source language to map between table columns and a TableModel.
- A binding language between web components and the underlying model objects (WebOGNL
, Tapestry
and WebWork
).
- A more expressive replacement for the property-getting language used by the Jakarta Commons BeanUtils
(which only allows simple property navigation and rudimentary indexed properties).
Most of what you can do in Java is possible in OGNL, plus other extras such as list projection and selection and lambda expressions.
Introduction
OGNL as a language allows for the navigation of Java objects through a concise syntax that allows for specifying, where possible, symmetrically settable and gettable values. The language specifies a syntax that attempts to provide as high a level of abstraction as possible for navigating object graphs; this usually means specifying paths through and to JavaBeans properties, collection, indices, etc. rather than directly accessing property getters and setters (collectively know as accessors).
The normal usage of OGNL is to embed the language inside of other constructs to provide a place for flexible binding of values from one place to another. An example of this is a web application where values need to be bound from a model of some sort to data transfer objects that are operated on by a view. Another example is an XML configuration file wherein values are generated via expressions which are then bound to configured objects.
Language Guide
Developers Guide