javax.faces.application
Class ViewHandlerWrapper

java.lang.Object
  extended by javax.faces.application.ViewHandler
      extended by javax.faces.application.ViewHandlerWrapper

public abstract class ViewHandlerWrapper
extends ViewHandler

see Javadoc of JSF Specification

Author:
Stan Silvert

Field Summary
 
Fields inherited from class javax.faces.application.ViewHandler
CHARACTER_ENCODING_KEY, DEFAULT_SUFFIX, DEFAULT_SUFFIX_PARAM_NAME
 
Constructor Summary
ViewHandlerWrapper()
           
 
Method Summary
 String calculateCharacterEncoding(FacesContext context)
           
 Locale calculateLocale(FacesContext context)
          Return the Locale object that should be used when rendering this view to the current user.
 String calculateRenderKitId(FacesContext context)
          Return the id of an available render-kit that should be used to map the JSF components into user presentation.
 UIViewRoot createView(FacesContext context, String viewId)
          Build a root node for a component tree.
 String getActionURL(FacesContext context, String viewId)
          Return a URL that a remote system can invoke in order to access the specified view.
 String getResourceURL(FacesContext context, String path)
          Return a URL that a remote system can invoke in order to access the specified resource.
protected abstract  ViewHandler getWrapped()
           
 void initView(FacesContext context)
          Method must be called by the JSF impl at the beginning of Phase Restore View of the JSF lifecycle.
 void renderView(FacesContext context, UIViewRoot viewToRender)
          Combine the output of all the components in the viewToRender with data from the original view template (if any) and write the result to context.externalContext.response.
 UIViewRoot restoreView(FacesContext context, String viewId)
          Handle a "postback" request by recreating the component tree that was most recently presented to the user for the specified view.
 void writeState(FacesContext context)
          Write sufficient information to context.externalContext.response in order to be able to restore this view if the user performs a "postback" using that rendered response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ViewHandlerWrapper

public ViewHandlerWrapper()
Method Detail

calculateCharacterEncoding

public String calculateCharacterEncoding(FacesContext context)
Overrides:
calculateCharacterEncoding in class ViewHandler

initView

public void initView(FacesContext context)
              throws FacesException
Description copied from class: ViewHandler
Method must be called by the JSF impl at the beginning of Phase Restore View of the JSF lifecycle.

Overrides:
initView in class ViewHandler
Throws:
FacesException

getWrapped

protected abstract ViewHandler getWrapped()

renderView

public void renderView(FacesContext context,
                       UIViewRoot viewToRender)
                throws IOException,
                       FacesException
Description copied from class: ViewHandler
Combine the output of all the components in the viewToRender with data from the original view template (if any) and write the result to context.externalContext.response.

Component output is generated by invoking the encodeBegin, encodeChildren (optional) and encodeEnd methods on relevant components in the specified view. How this is interleaved with the non-component content of the view template (if any) is left to the ViewHandler implementation.

The actual type of the Response object depends upon the concrete implementation of this class. It will almost certainly be an OutputStream of some sort, but may be specific to the particular request/response system in use.

If the view cannot be rendered (eg due to an error in a component) then a FacesException is thrown.

Note that if a "postback" has occurred but no navigation to a different view, then the viewToRender will be fully populated with components already. However on direct access to a new view, or when navigation has occurred, the viewToRender will just contain an empty UIViewRoot object that must be populated with components from the "view template".

Specified by:
renderView in class ViewHandler
Throws:
IOException
FacesException

writeState

public void writeState(FacesContext context)
                throws IOException
Description copied from class: ViewHandler
Write sufficient information to context.externalContext.response in order to be able to restore this view if the user performs a "postback" using that rendered response.

For "client side state saving", sufficient information about the view state should be written to allow a "restore view" operation to succeed later. This does not necessarily mean storing all data about the current view; only data that cannot be recreated from the "template" for this view needs to be saved.

For "server side state saving", this method may write out nothing. Alternately it may write out a "state identifier" to identify which of multiple saved user states for a particular view should be selected (or just verify that the saved state does indeed correspond to the expected one).

Specified by:
writeState in class ViewHandler
Throws:
IOException

calculateRenderKitId

public String calculateRenderKitId(FacesContext context)
Description copied from class: ViewHandler
Return the id of an available render-kit that should be used to map the JSF components into user presentation.

The render-kit selected (eg html, xhtml, pdf, xul, ...) may depend upon the user, properties associated with the request, etc.

Specified by:
calculateRenderKitId in class ViewHandler

calculateLocale

public Locale calculateLocale(FacesContext context)
Description copied from class: ViewHandler
Return the Locale object that should be used when rendering this view to the current user.

Some request protocols allow an application user to specify what locale they prefer the response to be in. For example, HTTP requests can specify the "accept-language" header.

Method Application.getSupportedLocales() defines what locales this JSF application is capable of supporting.

This method should match such sources of data up and return the Locale object that is the best choice for rendering the current application to the current user.

Specified by:
calculateLocale in class ViewHandler

restoreView

public UIViewRoot restoreView(FacesContext context,
                              String viewId)
Description copied from class: ViewHandler
Handle a "postback" request by recreating the component tree that was most recently presented to the user for the specified view.

When the user performs a "postback" of a view that has previously been created, ie is updating the state of an existing view tree, then the view handler must recreate a view tree identical to the one used previously to render that view to the user, so that the data received from the user can be compared to the old state and the correct "changes" detected (well, actually only those components that respond to input are actually needed before the render phase).

The components in this tree will then be given the opportunity to examine new input data provided by the user, and react in the appropriate manner for that component, as specified for the JSF lifecycle.

Much of the work required by this method must be delegated to an instance of StateManager.

If there is no record of the current user having been sent the specified view (ie no saved state information available), then NULL should be returned.

Note that input data provided by the user may also be used to determine exactly how to restore this view. In the case of "client side state", information about the components to be restored will be available here. Even for "server side state", user input may include an indicator that is used to select among a number of different saved states available for this viewId and this user.

Note that data received from users is inherently untrustworthy; care should be taken to validate this information appropriately.

See writeState for more details.

Specified by:
restoreView in class ViewHandler

getResourceURL

public String getResourceURL(FacesContext context,
                             String path)
Description copied from class: ViewHandler
Return a URL that a remote system can invoke in order to access the specified resource.

When path starts with a slash, it is relative to the webapp root. Otherwise it is relative to the value returned by getActionURL.

Specified by:
getResourceURL in class ViewHandler

getActionURL

public String getActionURL(FacesContext context,
                           String viewId)
Description copied from class: ViewHandler
Return a URL that a remote system can invoke in order to access the specified view.

Note that the URL a user enters and the viewId which is invoked can be different. The simplest difference is a change in suffix (eg url "foo.jsf" references view "foo.jsp").

Specified by:
getActionURL in class ViewHandler

createView

public UIViewRoot createView(FacesContext context,
                             String viewId)
Description copied from class: ViewHandler
Build a root node for a component tree.

When a request is received, this method is called if restoreView returns null, ie this is not a "postback". In this case, a root node is created and then renderView is invoked. It is the responsibility of the renderView method to build the full component tree (ie populate the UIViewRoot with descendant nodes).

This method is also invoked when navigation occurs from one view to another, where the viewId passed is the id of the new view to be displayed. Again it is the responsibility of renderView to then populate the viewroot with descendants.

The locale and renderKit settings are inherited from the current UIViewRoot that is configured before this method is called. That means of course that they do NOT get set for GET requests, including navigation that has the redirect flag set.

Specified by:
createView in class ViewHandler


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.