Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.web.servlet.view
Class JstlView

    java.lang.Object
      org.springframework.context.support.ApplicationObjectSupport
          org.springframework.web.context.support.WebApplicationObjectSupport
              org.springframework.web.servlet.view.AbstractView
                  org.springframework.web.servlet.view.AbstractUrlBasedView
                      org.springframework.web.servlet.view.InternalResourceView
                          org.springframework.web.servlet.view.JstlView

All Implemented Interfaces:
  Aware, BeanNameAware, InitializingBean, ApplicationContextAware, ServletContextAware, View

    public class JstlView

extends InternalResourceView

Specialization of `InternalResourceView` for JSTL pages, i.e. JSP pages that use the JSP Standard Tag Library.

Exposes JSTL-specific request attributes specifying locale and resource bundle for JSTL's formatting and message tags, using Spring's locale and `MessageSource`.

Typical usage with `InternalResourceViewResolver` would look as follows, from the perspective of the DispatcherServlet context definition:

     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
       <property name="prefix" value="/WEB-INF/jsp/"/>
       <property name="suffix" value=".jsp"/>
     </bean>

     <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
       <property name="basename" value="messages"/>
     </bean>

Every view name returned from a handler will be translated to a JSP resource (for example: "myView" -> "/WEB-INF/jsp/myView.jsp"), using this view class to enable explicit JSTL support.

The specified MessageSource loads messages from "messages.properties" etc files in the class path. This will automatically be exposed to views as JSTL localization context, which the JSTL fmt tags (message etc) will use. Consider using Spring's ReloadableResourceBundleMessageSource instead of the standard ResourceBundleMessageSource for more sophistication. Of course, any other Spring components can share the same MessageSource.

This is a separate class mainly to avoid JSTL dependencies in `InternalResourceView` itself. JSTL has not been part of standard J2EE up until J2EE 1.4, so we can't assume the JSTL API jar to be available on the class path.

Hint: Set the `InternalResourceView.setExposeContextBeansAsAttributes(boolean)` flag to "true" in order to make all Spring beans in the application context accessible within JSTL expressions (e.g. in a `c:out` value expression). This will also make all such beans accessible in plain `${...}` expressions in a JSP 2.0 page.

Since:
  27.02.2003
Author:
  Juergen Hoeller
See Also:
  `JstlUtils.exposeLocalizationContext(javax.servlet.http.HttpServletRequest, org.springframework.context.MessageSource)`, `InternalResourceViewResolver`, `ResourceBundleMessageSource`, `ReloadableResourceBundleMessageSource`

Field Summary

Fields inherited from class org.springframework.web.servlet.view.AbstractView
`DEFAULT_CONTENT_TYPE`

Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
`logger`

Fields inherited from interface org.springframework.web.servlet.View
`PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE`

Constructor Summary
`JstlView()` Constructor for use as a bean.
`JstlView(java.lang.String url)` Create a new JstlView with the given URL.
`JstlView(java.lang.String url, MessageSource messageSource)` Create a new JstlView with the given URL.

Method Summary
`protected void` | `exposeHelpers(javax.servlet.http.HttpServletRequest request)` Exposes a JSTL LocalizationContext for Spring's locale and MessageSource.
`protected void` | `initServletContext(javax.servlet.ServletContext servletContext)` Wraps the MessageSource with a JSTL-aware MessageSource that is aware of JSTL's `javax.servlet.jsp.jstl.fmt.localizationContext` context-param.

Methods inherited from class org.springframework.web.servlet.view.InternalResourceView
`exposeForwardRequestAttributes, getRequestDispatcher, getRequestToExpose, isContextRequired, prepareForRendering, renderMergedOutputModel, setAlwaysInclude, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposeForwardAttributes, setPreventDispatchLoop, useInclude`

Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView
`afterPropertiesSet, checkResource, getUrl, isUrlRequired, setUrl, toString`

Methods inherited from class org.springframework.web.servlet.view.AbstractView
`addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, generatesDownloadContent, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposePathVariables, setRequestContextAttribute, writeToResponse`

Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
`getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, setServletContext`

Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
`getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### JstlView

    public JstlView()

  Constructor for use as a bean.

  See Also:
    `AbstractUrlBasedView.setUrl(java.lang.String)`

### JstlView

    public JstlView(java.lang.String url)

  Create a new JstlView with the given URL.

  Parameters:
    `url` - the URL to forward to

### JstlView

    public JstlView(java.lang.String url,
                    MessageSource messageSource)

  Create a new JstlView with the given URL.

  Parameters:
    `url` - the URL to forward to
    `messageSource` - the MessageSource to expose to JSTL tags (will be wrapped with a JSTL-aware MessageSource that is aware of JSTL's `javax.servlet.jsp.jstl.fmt.localizationContext` context-param)
  See Also:
    `JstlUtils.getJstlAwareMessageSource(javax.servlet.ServletContext, org.springframework.context.MessageSource)`

Method Detail

### initServletContext

    protected void initServletContext(javax.servlet.ServletContext servletContext)

  Wraps the MessageSource with a JSTL-aware MessageSource that is aware of JSTL's `javax.servlet.jsp.jstl.fmt.localizationContext` context-param.

  Overrides:
    `initServletContext` in class `InternalResourceView`
  Parameters:
    `servletContext` - the ServletContext that this application object runs in (never `null`)
  See Also:
    `JstlUtils.getJstlAwareMessageSource(javax.servlet.ServletContext, org.springframework.context.MessageSource)`

### exposeHelpers

    protected void exposeHelpers(javax.servlet.http.HttpServletRequest request)
                          throws java.lang.Exception

  Exposes a JSTL LocalizationContext for Spring's locale and MessageSource.

  Overrides:
    `exposeHelpers` in class `InternalResourceView`
  Parameters:
    `request` - current HTTP request
  Throws:
    `java.lang.Exception` - if there's a fatal error while we're adding attributes
  See Also:
    `JstlUtils.exposeLocalizationContext(javax.servlet.http.HttpServletRequest, org.springframework.context.MessageSource)`

Overview | Package | Class | Tree | Deprecated | Index | Help
| Spring Framework
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD