Accessing Spring beans from a Tiles view (JSP)

前端 未结 3 1344
逝去的感伤
逝去的感伤 2020-12-03 01:33

In Spring MVC I can access my beans in JSP using JstlView\'s exposedContextBeanNames (or exposeContextBeansAsAttributes). For example, then, in my JSP I can write (${propert

3条回答
  •  盖世英雄少女心
    2020-12-03 02:15

    As you've noticed, this functionality is part of InternalResourceViewResolver and InternalResourceView, whereas the Tiles stuff inherits directly from UrlBasedViewResolver and AbstractUrlBasedView, so you can't make use of it.

    Looking at the code, there's no reason why this stuff couldn't have been put into AbstractUrlBasedView. The magic happens in InternalResourceView.getRequestToExpose, and it looks perfectly applicable to AbstractUrlBasedView too.

    In the short term, I suggest subclassing UrlBasedViewResolver and TilesView, copying the getRequestToExpose stuff from InternalResourceView. In the longer term, I encourage you to file a issue with SpringSource asking them to move this functionality up the class hierarchy into AbstractUrlBasedView, making it more widely available.

提交回复
热议问题