본문 바로가기

카테고리 없음

OGNL


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.

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).

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:

...........................................................................................................................................................................................................

<s:property value="name" />
에서 property 태그는 value의 값을 OGNL로 평가한다.
#표시가 없는 OGNL 표현식 name은 루트 오브젝트의 property이다.
스트럿츠2에서 루트 오브젝트는 value stack이고 value stack 상단에 액션이 있으므로 "name"은 항상 액션의 property가 된다.
JSP EL의 ${name}과 같다.

<s:property value="#session.user" />
루트 오브젝트가 아닌 세션 맵의 user를 참조할 때는 위와 같이 "#"을 붙여서 오브젝트 이름과 프라퍼티 또는 맵의 키를 사용해서 참조한다. 루트 오브젝트의 프라퍼티만 프라퍼티 이름만으로 참조 할 수 있다.
JSP EL의 ${sessionScope.user }와 같다.

스트럿츠 2 태그에서 %{...}가 OGNL의 표현식이다. 즉 %{...}내의 텍스트는 OGNL 표현식으로 평가된다.
%{name}이라 하면 문자열 name이 아니고 name을 OGNL 표현식으로 평가한다..
따라서 %{name}은 액션의 name의 프라퍼티 값이 된다.