Question

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

Was it helpful?

Solution

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.

OTHER TIPS

I don't think it is possible to do even if you choose not to use OGNL with your struts2 web application. OGNL is used internally by struts2 for data transfer and type conversion. If you're planning to use struts2, you'll have to use OGNL and if u don't do it, struts2 will do it automatically.

Although you may leave out OGNL And use pure EL, but that way the whole purpose of using struts2 gets defeated cause if you're not using built-in features of struts2, you're probably writing those mechanisms from scratch using EL.

Although it may seem odd initially, but OGNL is quite powerful and worth considering when developing in struts2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top