Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing EL in JSP with SpEL from Spring 3.0

Tired of old EL in JSP not being able to invoke methods on beans etc.

Can I use SpEL from Spring 3.0 in my JSP:s?

like image 755
D. Wroblewski Avatar asked Dec 22 '09 09:12

D. Wroblewski


People also ask

What is the use of SpEL in spring?

The Spring Expression Language (SpEL) is a powerful expression language that supports querying and manipulating an object graph at runtime. We can use it with XML or annotation-based Spring configurations.

What are the features of SpEL?

SpEL supports a wide range of features, such as calling methods, accessing properties, and calling constructors. As an example of method invocation, we call the 'concat' method on the string literal. ExpressionParser parser = new SpelExpressionParser(); Expression exp = parser. parseExpression("'Hello World'.

Is expression language a part of core Spring Framework?

While there are several other Java expression languages available, OGNL, MVEL, and JBoss EL, to name a few, the Spring Expression Language was created to provide the Spring community with a single well supported expression language that can be used across all the products in the Spring portfolio.


2 Answers

The upcoming Spring Framework 3.0.1 release adds a new spring:eval JSP tag that allows you to evaluate SpEL expressions from JSP pages.

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

Future versions will add native integration with JSP 2.1 or > engines via a Unified EL adaption layer.

like image 121
kdonald Avatar answered Nov 15 '22 18:11

kdonald


It would be nice, wouldn't it, but no, JSP EL is a function of the JSP compiler. The best you could do would be to write a custom taglib which evaluated contained SpEL expressions, which would be rather clunky.

like image 27
skaffman Avatar answered Nov 15 '22 16:11

skaffman