Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantages of OGNL usage over typical EL in Struts2

Tags:

el

struts2

ognl

Say that I don't leverage OGNL to create my Struts2 web application and just purely uses typical el provided by Sun. What would be the downside of it?

As far as I know, OGNL is a kind of expression which attempts to match the best matched value from ValueStack based on its current state. Could it also be achieved by just using EL alone instead?

Thanks in advance for the responses

Daniel

like image 630
Daniel Avatar asked Jan 14 '10 03:01

Daniel


People also ask

What is OGNL in struts2?

OGNL is the Object Graph Navigation Language (see [http://commons.apache.org/proper/commons-ognl/] for the full documentation of OGNL).

What is the purpose of valueStack and OGNL explain valueStack OGNL with an example?

ValueStack/OGNL Example Actually, Struts 2 adds your action to the top of the valueStack when executed. So, the usual way to put stuff on the Value Stack is to add getters/setters for the values to your Action class and then use <s:property> tag to access the values.

What is OGNL used for?

Object-Graph Navigation Language (OGNL) is an open-source Expression Language (EL) for Java, which, while using simpler expressions than the full range of those supported by the Java language, allows getting and setting properties (through defined setProperty and getProperty methods, found in JavaBeans), and execution ...

What is OGNL evaluation?

Object-Graph Navigation Language is an open-source Expression Language (EL) for Java objects. Specifically, OGNL enables the evaluation of EL expressions in Apache Struts, which is the commonly used development framework for Java-based web applications in enterprise environments.


1 Answers

Short Answer: Yes, you can use the JSP EL instead of OGNL. Both languages have their pros and cons, but there is no looming downside to using either.

Long Answer: OGNL is used internally by XWork and Struts2, so you can't actually remove the dependency itself, however you can certainly use the JSP EL predominantly (or even exclusively) in your JSP view layer.

There are pros and cons to using either expression language. One area that OGNL shines over the JSP EL is in dynamic creation of maps and collections, such as for backing <select/> elements, etc.

However, in most cases I find that the JSP EL is a better fit for me since I make heavy use of JSP simple tags (.tag files).

@Amit Sharma: I have to disagree that using JSP/JSTL over OGNL and the Struts tags defeats the purpose of using Struts2. The interceptor framework, type conversion, and result types are among the most extensible and compelling reasons to use Struts2. None of those things are tied to any specific view technology.

like image 146
Steven Benitez Avatar answered Sep 27 '22 02:09

Steven Benitez