Benefits of using OGNL over typical EL in Struts2

Say that I am not using OGNL to build my Struts2 web application and just use the regular el provided by Sun. What would be a disadvantage?

As far as I know, OGNL is a kind of expression that tries to match the best consistent value of a ValueStack based on its current state. Could this also be achieved simply by using only EL?

Thanks in advance for your answers.

Daniel

+7
el struts2 ognl
source share
2 answers

Short answer: Yes, you can use JSP EL instead of OGNL. Both languages ​​have their pros and cons, but there is no obvious drawback to use.

Long answer: OGNL is used internally by XWork and Struts2, so you can’t actually remove the dependency itself, however you can use JSP EL primarily (or even exclusively) in your JSP presentation level.

There are pros and cons to using an expression language. One area that OGNL shines on JSP EL is the dynamic creation of maps and collections, for example, to support <select/> elements, etc.

However, in most cases, I find that JSP EL is better for me, as I heavily use simple JSP tags ( .tag ).

@Amit Sharma: I have to disagree that using JSP / JSTL over OGNL and Struts tags strikes the purpose of using Struts2. Interceptor structure, type conversion, and result types are some of the most extensible and compelling reasons to use Struts2. None of these things are related to any particular viewing technology.

+9
source share

I do not think this is possible, even if you decide not to use OGNL with your struts2 web application. OGNL is used internally by struts2 for data transfer and type conversion. If you plan to use struts2, you will need to use OGNL, and if you do not, struts2 will do this automatically.

Although you can leave OGNL and use pure EL, but in this case the whole purpose of using struts2 will be defeated if you do not use the built-in functions of struts2, you are probably writing these mechanisms from scratch using EL.

Although this may seem strange at first, OGNL is strong enough and worth considering when developing in struts2.

+2
source share

All Articles