org.apache.shale.clay.faces
Class ClayViewHandler

java.lang.Object
  extended by javax.faces.application.ViewHandler
      extended by org.apache.shale.clay.faces.ClayViewHandler

public class ClayViewHandler
extends javax.faces.application.ViewHandler

This ViewHandler will handle full HTML template views using the Clay component as the single subtree under the view root. Views will be intercepted having a suffix matching the registered clay template suffix in the web deployment descriptor. The default suffixes are ".html" and "*.xml". All other view render requests that don't match the suffixes will be delegated to the original decorated view handler.


Field Summary
protected static String[] FORM_MARKERS
          HTML form markers for client side state saving for MyFaces and Sun RI implementations.
static String VIEW_MAPPER
          Application scope attribute under which the ViewControllerMapper for translating view identifiers to class names of the corresponding ViewController is stored.
 
Fields inherited from class javax.faces.application.ViewHandler
CHARACTER_ENCODING_KEY, DEFAULT_SUFFIX, DEFAULT_SUFFIX_PARAM_NAME
 
Constructor Summary
ClayViewHandler(javax.faces.application.ViewHandler original)
          This is an overloaded constructor passing the original view handler.
 
Method Summary
 Locale calculateLocale(javax.faces.context.FacesContext context)
           
 String calculateRenderKitId(javax.faces.context.FacesContext context)
           
 javax.faces.component.UIViewRoot createView(javax.faces.context.FacesContext context, String viewId)
          This method is overridden to check to see if the target view is a clay html or xml template.
 String getActionURL(javax.faces.context.FacesContext context, String viewId)
           If the viewId is suffixed with the Clay template suffix, rewrite the returned actionUrl with a clay suffix.
protected  String getManagedBeanName(javax.faces.context.FacesContext context, String viewId)
          Returns the "@managed-bean-name" the view controller is registered under.
 String getResourceURL(javax.faces.context.FacesContext context, String path)
           
protected  int indexOfClayTemplateSuffix(javax.faces.context.FacesContext context, String viewId)
          This method looks to see if the target view identified by the viewId is a Clay HTML or XML full view.
protected  int indexOfFormMarker()
          Returns an index into the FORM_MAKKERS array.
protected  void recursiveRender(javax.faces.component.UIComponent child, javax.faces.context.FacesContext context)
           Recursively invokes the rendering of the sub component tree.
 void renderView(javax.faces.context.FacesContext context, javax.faces.component.UIViewRoot view)
          The viewId is check to see if it ends with the same suffix as the full HTML or XML views.
 javax.faces.component.UIViewRoot restoreView(javax.faces.context.FacesContext context, String viewId)
          The default view handler implementation will try to make the viewId end with ".jsp".
 void writeState(javax.faces.context.FacesContext context)
          Invokes the original view handler's writeState.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VIEW_MAPPER

public static final String VIEW_MAPPER

Application scope attribute under which the ViewControllerMapper for translating view identifiers to class names of the corresponding ViewController is stored.

See Also:
Constant Field Values

FORM_MARKERS

protected static final String[] FORM_MARKERS

HTML form markers for client side state saving for MyFaces and Sun RI implementations.

Constructor Detail

ClayViewHandler

public ClayViewHandler(javax.faces.application.ViewHandler original)

This is an overloaded constructor passing the original view handler.

Parameters:
original - view handler
Method Detail

calculateLocale

public Locale calculateLocale(javax.faces.context.FacesContext context)
Specified by:
calculateLocale in class javax.faces.application.ViewHandler
Parameters:
context - faces context
Returns:
locale calculated from the original handler

calculateRenderKitId

public String calculateRenderKitId(javax.faces.context.FacesContext context)
Specified by:
calculateRenderKitId in class javax.faces.application.ViewHandler
Parameters:
context - faces context
Returns:
render kit id calculated from the original handler

createView

public javax.faces.component.UIViewRoot createView(javax.faces.context.FacesContext context,
                                                   String viewId)

This method is overridden to check to see if the target view is a clay html or xml template. If it is, the view id is normalized before the original implementation is invoked.

Specified by:
createView in class javax.faces.application.ViewHandler
Parameters:
context - faces context
viewId - name of the page
Returns:
root of the component tree for the view id

getActionURL

public String getActionURL(javax.faces.context.FacesContext context,
                           String viewId)

If the viewId is suffixed with the Clay template suffix, rewrite the returned actionUrl with a clay suffix. The super implementation will assume ".jsp" or whatever the javax.faces.DEFAULT_SUFFIX is set to in the web deployment descriptor.

Specified by:
getActionURL in class javax.faces.application.ViewHandler
Parameters:
context - faces context
viewId - name of the page
Returns:
action attribute of the UIForm component

getResourceURL

public String getResourceURL(javax.faces.context.FacesContext context,
                             String path)
Specified by:
getResourceURL in class javax.faces.application.ViewHandler
Parameters:
context - faces context
path - context root relative path
Returns:
full path to the resource

indexOfClayTemplateSuffix

protected int indexOfClayTemplateSuffix(javax.faces.context.FacesContext context,
                                        String viewId)

This method looks to see if the target view identified by the viewId is a Clay HTML or XML full view. This is determined by a value cached in request scope by the ClayViewHandlerCommand or the suffix of the viewId. If a match is found, the index position into the suffixes array is returned; Otherwise a -1 is returned.

Parameters:
context - faces context
viewId - name of the page
Returns:
index into the suffixes array or -1 if not found

restoreView

public javax.faces.component.UIViewRoot restoreView(javax.faces.context.FacesContext context,
                                                    String viewId)

The default view handler implementation will try to make the viewId end with ".jsp". If the viewId ends in the clay template suffix, use the state manager to restore the view.

Specified by:
restoreView in class javax.faces.application.ViewHandler
Parameters:
context - faces context
viewId - name of the page
Returns:
root of the page

writeState

public void writeState(javax.faces.context.FacesContext context)
                throws IOException

Invokes the original view handler's writeState.

Specified by:
writeState in class javax.faces.application.ViewHandler
Parameters:
context - faces context
Throws:
IOException - serializing tree

indexOfFormMarker

protected int indexOfFormMarker()

Returns an index into the FORM_MAKKERS array. The index will be used to get the form marker matching the JSF runtime. Only the myfaces and Sun RI are supported. The form marker is determined by trying to load the myfaces view handler. Next, the Sun RI 1.2 JSPVersionTracker is attempted to be loaded. The default is the marker for the Sun RI.

Returns:
index into the FORM_MARKERS array

renderView

public void renderView(javax.faces.context.FacesContext context,
                       javax.faces.component.UIViewRoot view)
                throws IOException

The viewId is check to see if it ends with the same suffix as the full HTML or XML views. This match might be performed by the ClayViewHandlerCommand when using the myfaces jsf implementation. If a match is not found, control is passed to the decorated view handler. Otherwise, a Clay component is instantiated as a single subtree under the view root. The component's id property is set with a constant, CLAY_VIEW_ID. The jsfid property is set to the viewId. The managedBeanName property is set with the Shale ViewControllerMapper. A ResponseWriter is created and rendering is invoked on the component. This differs from the base implementation. The base implementation would dispatch to a JSP that would assemble the component tree and invoke rendering to the response writer.

Specified by:
renderView in class javax.faces.application.ViewHandler
Parameters:
context - faces context
view - root of the component tree
Throws:
IOException - response writer

recursiveRender

protected void recursiveRender(javax.faces.component.UIComponent child,
                               javax.faces.context.FacesContext context)
                        throws IOException

Recursively invokes the rendering of the sub component tree.

Parameters:
child - component to invoke renderering on
context - faces context
Throws:
IOException - writing markup

getManagedBeanName

protected String getManagedBeanName(javax.faces.context.FacesContext context,
                                    String viewId)

Returns the "@managed-bean-name" the view controller is registered under. The assumed mapping will be the same as in core Shale.

Parameters:
context - faces context
viewId - name of the page
Returns:
default managed bean name associated with the view


Copyright © 2004-2007 Apache Software Foundation. All Rights Reserved.