JSF-Spring

de.mindmatters.faces.spring.context.servlet
Class FacesView

java.lang.Object
  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.view.AbstractView
              extended by org.springframework.web.servlet.view.AbstractUrlBasedView
                  extended by de.mindmatters.faces.spring.context.servlet.FacesView
All Implemented Interfaces:
BeanNameAware, InitializingBean, ApplicationContextAware, ServletContextAware, View

public class FacesView
extends AbstractUrlBasedView

Wrapper for a JSP or other resource within the same faces web application.

Rendering is delegated to the Lifecycle of the underlying JSF implementation.

UIViewRoot creation is done by this class (if not already created by other components such as a NavigationHandler).

Typical usage with FacesViewResolver would look as follows, from the perspective of the FacesDispatcherServlet context definition:

 <bean id="viewResolver" class="de.mindmatters.faces.spring.context.servlet.FacesViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
 </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 by default.

Author:
Andreas Kuhrwahl
See Also:
Lifecycle.render(FacesContext), ViewHandler.createView(FacesContext, String)

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
 
Constructor Summary
FacesView()
          Constructor for use as a bean.
FacesView(java.lang.String url)
          Create a new FacesView with the given URL url.
FacesView(UIViewRoot viewRoot)
          Create a new FacesView with the given UIViewRoot viewRoot.
 
Method Summary
 void afterPropertiesSet()
          Resolves the appropriate Lifecycle depending on the configured lifecycle-id.
protected  void exposeHelpers(javax.servlet.http.HttpServletRequest request)
          Expose helpers unique to each rendering operation.
protected  void exposeViewRootIfNecessary(FacesContext context, java.lang.String viewId)
          Creates and exposes the UIViewRoot to the given FacesContext if necessary.
protected  Lifecycle getLifecycle()
           
protected  void initFacesView()
          This hook method will be invoked after any bean properties have been set and the Lifecycle has been resolved.
protected  java.lang.String prepareViewIdForRendering(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Prepare for rendering, and determine the the view id to render by the resolved Lifecycle.
protected  void render(FacesContext context)
          Renders the appropriate view with the help of the resolved Lifecycle.
protected  void renderMergedOutputModel(java.util.Map model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Subclasses must implement this method to actually render the view.
 void setLifecycleId(java.lang.String lifecycleId)
          Sets the lifecycle-id for resolving the appropriate Lifecycle.
 
Methods inherited from class org.springframework.web.servlet.view.AbstractUrlBasedView
getUrl, setUrl, toString
 
Methods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createRequestContext, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setRequestContextAttribute
 
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, isContextRequired, 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

FacesView

public FacesView()
Constructor for use as a bean.


FacesView

public FacesView(java.lang.String url)
Create a new FacesView with the given URL url.

Parameters:
url - the URL to forward to

FacesView

public FacesView(UIViewRoot viewRoot)
Create a new FacesView with the given UIViewRoot viewRoot.

Parameters:
viewRoot - the UIViewRoot to render
Method Detail

afterPropertiesSet

public final void afterPropertiesSet()
                              throws java.lang.Exception
Resolves the appropriate Lifecycle depending on the configured lifecycle-id.

Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class AbstractUrlBasedView
Throws:
java.lang.Exception - in the case of errors
See Also:
setLifecycleId(String)

initFacesView

protected void initFacesView()
This hook method will be invoked after any bean properties have been set and the Lifecycle has been resolved. The default implementation is empty; subclasses may override this method to perform any initialization they require.


getLifecycle

protected final Lifecycle getLifecycle()
Returns:
The resolved Lifecycle that will be used by this View for rendering.

setLifecycleId

public final void setLifecycleId(java.lang.String lifecycleId)
Sets the lifecycle-id for resolving the appropriate Lifecycle.

Parameters:
lifecycleId - the lifecycle-id identifying the Lifecycle to use

exposeHelpers

protected void exposeHelpers(javax.servlet.http.HttpServletRequest request)
                      throws java.lang.Exception
Expose helpers unique to each rendering operation. This is necessary so that different rendering operations can't overwrite each other's contexts etc.

Called by renderMergedOutputModel(Map, HttpServletRequest, HttpServletResponse). The default implementation is empty. This method can be overridden to add custom helpers as request attributes.

Parameters:
request - current HTTP request
Throws:
java.lang.Exception - if there's a fatal error while we're adding attributes
See Also:
renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

prepareViewIdForRendering

protected java.lang.String prepareViewIdForRendering(javax.servlet.http.HttpServletRequest request,
                                                     javax.servlet.http.HttpServletResponse response)
                                              throws java.lang.Exception
Prepare for rendering, and determine the the view id to render by the resolved Lifecycle.

This implementation simply returns the configured URL. Subclasses can override this to determine a resource to render, typically interpreting the URL in a different manner.

Parameters:
request - current HTTP request
response - current HTTP response
Returns:
the request dispatcher path to use
Throws:
java.lang.Exception - if preparations failed
See Also:
AbstractUrlBasedView.getUrl()

renderMergedOutputModel

protected final void renderMergedOutputModel(java.util.Map model,
                                             javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.http.HttpServletResponse response)
                                      throws java.lang.Exception
Subclasses must implement this method to actually render the view.

The first step will be preparing the request: In the JSP case, this would mean setting model objects as request attributes. The second step will be the actual rendering of the view, for example including the JSP via a RequestDispatcher.

Specified by:
renderMergedOutputModel in class AbstractView
Parameters:
model - combined output Map (never null), with dynamic values taking precedence over static attributes
request - current HTTP request
response - current HTTP response
Throws:
java.lang.Exception - if rendering failed

exposeViewRootIfNecessary

protected void exposeViewRootIfNecessary(FacesContext context,
                                         java.lang.String viewId)
Creates and exposes the UIViewRoot to the given FacesContext if necessary. This could be the case if the creation of the UIViewRoot is not done yet by another component such as the NavigationHandler.

Parameters:
context - FacesContext for the current request
viewId - the prepared view identifier of the view to render
See Also:
FacesContext.getRenderResponse()

render

protected void render(FacesContext context)
Renders the appropriate view with the help of the resolved Lifecycle.

Parameters:
context - FacesContext for the current request
Throws:
FacesException - if an exception is thrown during the rendering
See Also:
Lifecycle.render(FacesContext)

JSF-Spring

Copyright © 2006 mindmatters GmbH & Co. KG