org.springframework.extensions.webscripts.ui.common
Class JSFUtils

java.lang.Object
  extended by org.springframework.extensions.webscripts.ui.common.JSFUtils

public final class JSFUtils
extends Object

Class containing misc helper methods for managing JSF Components. NOTE: Extracted from org.alfresco.web.ui.common.Utils;

Author:
Kevin Roast

Method Summary
static String buildImageTag(javax.faces.context.FacesContext context, String image, int width, int height, String alt)
          Build a context path safe image tag for the supplied image path.
static String buildImageTag(javax.faces.context.FacesContext context, String image, int width, int height, String alt, String onclick)
          Build a context path safe image tag for the supplied image path.
static String buildImageTag(javax.faces.context.FacesContext context, String image, int width, int height, String alt, String onclick, String verticalAlign)
          Build a context path safe image tag for the supplied image path.
static String buildImageTag(javax.faces.context.FacesContext context, String image, String alt)
          Build a context path safe image tag for the supplied image path.
static String buildImageTag(javax.faces.context.FacesContext context, String image, String alt, String verticalAlign)
          Build a context path safe image tag for the supplied image path.
static void encodeRecursive(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Helper to recursively render a component and it's child components
static String generateFormSubmit(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Generate the JavaScript to submit the parent Form.
static String generateFormSubmit(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String fieldId, String fieldValue)
          Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form.
static String generateFormSubmit(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String fieldId, String fieldValue, boolean valueIsParam, Map<String,String> params)
          Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form.
static String generateFormSubmit(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, String fieldId, String fieldValue, Map<String,String> params)
          Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form.
static String getActionHiddenFieldName(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Get the hidden field name for any action component.
static javax.faces.component.UIForm getParentForm(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Return the parent UIForm component for the specified UIComponent
static javax.faces.component.UIComponent getParentNamingContainer(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Return the parent UIComponent implementing the NamingContainer interface for the specified UIComponent.
static boolean isComponentDisabledOrReadOnly(javax.faces.component.UIComponent component)
          Determines whether the given component is disabled or readonly
static void outputAttribute(javax.faces.context.ResponseWriter out, Object attr, String mapping)
          Helper to output an attribute to the output stream
static void processActionMethod(javax.faces.context.FacesContext context, javax.faces.el.MethodBinding method, javax.faces.event.ActionEvent event)
          Invoke the method encapsulated by the supplied MethodBinding
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

outputAttribute

public static void outputAttribute(javax.faces.context.ResponseWriter out,
                                   Object attr,
                                   String mapping)
                            throws IOException
Helper to output an attribute to the output stream

Parameters:
out - ResponseWriter
attr - attribute value object (cannot be null)
mapping - mapping to output as e.g. style="..."
Throws:
IOException

getActionHiddenFieldName

public static String getActionHiddenFieldName(javax.faces.context.FacesContext context,
                                              javax.faces.component.UIComponent component)
Get the hidden field name for any action component. All components that wish to simply encode a form value with their client ID can reuse the same hidden field within the parent form. NOTE: components which use this method must only encode their client ID as the value and nothing else! Build a shared field name from the parent form name and the string "act".

Returns:
hidden field name shared by all action components within the Form.

encodeRecursive

public static void encodeRecursive(javax.faces.context.FacesContext context,
                                   javax.faces.component.UIComponent component)
                            throws IOException
Helper to recursively render a component and it's child components

Parameters:
context - FacesContext
component - UIComponent
Throws:
IOException

generateFormSubmit

public static String generateFormSubmit(javax.faces.context.FacesContext context,
                                        javax.faces.component.UIComponent component,
                                        String fieldId,
                                        String fieldValue)
Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form. NOTE: the supplied hidden field name is added to the Form Renderer map for output.

Parameters:
context - FacesContext
component - UIComponent to generate JavaScript for
fieldId - Hidden field id to set value for
fieldValue - Hidden field value to set hidden field too on submit
Returns:
JavaScript event code

generateFormSubmit

public static String generateFormSubmit(javax.faces.context.FacesContext context,
                                        javax.faces.component.UIComponent component,
                                        String fieldId,
                                        String fieldValue,
                                        Map<String,String> params)
Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form. NOTE: the supplied hidden field name is added to the Form Renderer map for output.

Parameters:
context - FacesContext
component - UIComponent to generate JavaScript for
fieldId - Hidden field id to set value for
fieldValue - Hidden field value to set hidden field too on submit
params - Optional map of param name/values to output
Returns:
JavaScript event code

generateFormSubmit

public static String generateFormSubmit(javax.faces.context.FacesContext context,
                                        javax.faces.component.UIComponent component,
                                        String fieldId,
                                        String fieldValue,
                                        boolean valueIsParam,
                                        Map<String,String> params)
Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form. NOTE: the supplied hidden field name is added to the Form Renderer map for output.

Parameters:
context - FacesContext
component - UIComponent to generate JavaScript for
fieldId - Hidden field id to set value for
fieldValue - Hidden field value to set hidden field too on submit
valueIsParam - Determines whether the fieldValue parameter should be treated as a parameter in the generated JavaScript, false will treat the value i.e. surround it with single quotes
params - Optional map of param name/values to output
Returns:
JavaScript event code

generateFormSubmit

public static String generateFormSubmit(javax.faces.context.FacesContext context,
                                        javax.faces.component.UIComponent component)
Generate the JavaScript to submit the parent Form.

Parameters:
context - FacesContext
component - UIComponent to generate JavaScript for
Returns:
JavaScript event code

buildImageTag

public static String buildImageTag(javax.faces.context.FacesContext context,
                                   String image,
                                   int width,
                                   int height,
                                   String alt,
                                   String onclick)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
width - Width in pixels
height - Height in pixels
alt - Optional alt/title text
onclick - JavaScript onclick event handler code
Returns:
Populated img tag

buildImageTag

public static String buildImageTag(javax.faces.context.FacesContext context,
                                   String image,
                                   int width,
                                   int height,
                                   String alt,
                                   String onclick,
                                   String verticalAlign)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
width - Width in pixels
height - Height in pixels
alt - Optional alt/title text
onclick - JavaScript onclick event handler code
verticalAlign - Optional HTML alignment value
Returns:
Populated img tag

buildImageTag

public static String buildImageTag(javax.faces.context.FacesContext context,
                                   String image,
                                   int width,
                                   int height,
                                   String alt)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
width - Width in pixels
height - Height in pixels
alt - Optional alt/title text
Returns:
Populated img tag

buildImageTag

public static String buildImageTag(javax.faces.context.FacesContext context,
                                   String image,
                                   String alt)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
alt - Optional alt/title text
Returns:
Populated img tag

buildImageTag

public static String buildImageTag(javax.faces.context.FacesContext context,
                                   String image,
                                   String alt,
                                   String verticalAlign)
Build a context path safe image tag for the supplied image path. Image path should be supplied with a leading slash '/'.

Parameters:
context - FacesContext
image - The local image path from the web folder with leading slash '/'
alt - Optional alt/title text
verticalAlign - Optional HTML alignment value
Returns:
Populated img tag

getParentForm

public static javax.faces.component.UIForm getParentForm(javax.faces.context.FacesContext context,
                                                         javax.faces.component.UIComponent component)
Return the parent UIForm component for the specified UIComponent

Parameters:
context - FaceContext
component - The UIComponent to find parent Form for
Returns:
UIForm parent or null if none found in hiearachy

getParentNamingContainer

public static javax.faces.component.UIComponent getParentNamingContainer(javax.faces.context.FacesContext context,
                                                                         javax.faces.component.UIComponent component)
Return the parent UIComponent implementing the NamingContainer interface for the specified UIComponent.

Parameters:
context - FaceContext
component - The UIComponent to find parent Form for
Returns:
NamingContainer parent or null if none found in hiearachy

isComponentDisabledOrReadOnly

public static boolean isComponentDisabledOrReadOnly(javax.faces.component.UIComponent component)
Determines whether the given component is disabled or readonly

Parameters:
component - The component to test
Returns:
true if the component is either disabled or set to readonly

processActionMethod

public static void processActionMethod(javax.faces.context.FacesContext context,
                                       javax.faces.el.MethodBinding method,
                                       javax.faces.event.ActionEvent event)
Invoke the method encapsulated by the supplied MethodBinding

Parameters:
context - FacesContext
method - MethodBinding to invoke
event - ActionEvent to pass to the method of signature: public void myMethodName(ActionEvent event)


Copyright © 2009 SpringSource, Inc. All Rights Reserved.