Pivotal Knowledge Base

Follow

Can Spring:Eval Work Inside a JSP Page Without a Controller?

Environment

 Product   Version
 Spring  All

Purpose 

You may access a bean, bean property, bean method, or system properties using the @Value. For example:

@Repository 

   public class myTestBean{

                  @Value("#{someBean.getSomeElementList}")
                  public void setSomeElementList(ElementList thisList) {
                  ... 
                            }
                          } 
                        }

Note: systemProperties is a predefined variable and someBean is the name of the bean.

Using the exact Spring Expression Language inside <spring:eval> (which was introduced in Spring version 3.0.1) in a view or JSP,

<spring:eval ="#{someBean.getSomeElementList()}" var="someList"/ >

The same expression language used in myTestBean will not work on JSP inside <spring:eval> without the use of controllers. This article explains how we can make this specific expression language work with the use of controllers. 

Resolution

<spring:eval> is not to be used in JSP without using a Controller. As of writing this article, to access beans i.e. someBean as described in the above code is only feasible if it is exposed to the view. An example for that is:

@Controller
public class MyController {
@Autowired
private SomeBean someBean public  ModelAndView handleGetView() { ModelAndView mav = new ModelAndView();                    mav.setViewName("myjsp"); mav.addObject("someBean", someBean); return mav; }

Comments

Powered by Zendesk