Class JSFUtils


  • public final class JSFUtils
    extends java.lang.Object
    Class containing misc helper methods for managing JSF Components. NOTE: Extracted from org.alfresco.web.ui.common.Utils;
    Author:
    Kevin Roast
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String buildImageTag​(javax.faces.context.FacesContext context, java.lang.String image, int width, int height, java.lang.String alt)
      Build a context path safe image tag for the supplied image path.
      static java.lang.String buildImageTag​(javax.faces.context.FacesContext context, java.lang.String image, int width, int height, java.lang.String alt, java.lang.String onclick)
      Build a context path safe image tag for the supplied image path.
      static java.lang.String buildImageTag​(javax.faces.context.FacesContext context, java.lang.String image, int width, int height, java.lang.String alt, java.lang.String onclick, java.lang.String verticalAlign)
      Build a context path safe image tag for the supplied image path.
      static java.lang.String buildImageTag​(javax.faces.context.FacesContext context, java.lang.String image, java.lang.String alt)
      Build a context path safe image tag for the supplied image path.
      static java.lang.String buildImageTag​(javax.faces.context.FacesContext context, java.lang.String image, java.lang.String alt, java.lang.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 java.lang.String generateFormSubmit​(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
      Generate the JavaScript to submit the parent Form.
      static java.lang.String generateFormSubmit​(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String fieldId, java.lang.String fieldValue)
      Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form.
      static java.lang.String generateFormSubmit​(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String fieldId, java.lang.String fieldValue, boolean valueIsParam, java.util.Map<java.lang.String,​java.lang.String> params)
      Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form.
      static java.lang.String generateFormSubmit​(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String fieldId, java.lang.String fieldValue, java.util.Map<java.lang.String,​java.lang.String> params)
      Generate the JavaScript to submit set the specified hidden Form field to the supplied value and submit the parent Form.
      static java.lang.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, java.lang.Object attr, java.lang.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,
                                           java.lang.Object attr,
                                           java.lang.String mapping)
                                    throws java.io.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:
        java.io.IOException
      • getActionHiddenFieldName

        public static java.lang.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 java.io.IOException
        Helper to recursively render a component and it's child components
        Parameters:
        context - FacesContext
        component - UIComponent
        Throws:
        java.io.IOException
      • generateFormSubmit

        public static java.lang.String generateFormSubmit​(javax.faces.context.FacesContext context,
                                                          javax.faces.component.UIComponent component,
                                                          java.lang.String fieldId,
                                                          java.lang.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 java.lang.String generateFormSubmit​(javax.faces.context.FacesContext context,
                                                          javax.faces.component.UIComponent component,
                                                          java.lang.String fieldId,
                                                          java.lang.String fieldValue,
                                                          java.util.Map<java.lang.String,​java.lang.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 java.lang.String generateFormSubmit​(javax.faces.context.FacesContext context,
                                                          javax.faces.component.UIComponent component,
                                                          java.lang.String fieldId,
                                                          java.lang.String fieldValue,
                                                          boolean valueIsParam,
                                                          java.util.Map<java.lang.String,​java.lang.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 java.lang.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 java.lang.String buildImageTag​(javax.faces.context.FacesContext context,
                                                     java.lang.String image,
                                                     int width,
                                                     int height,
                                                     java.lang.String alt,
                                                     java.lang.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 java.lang.String buildImageTag​(javax.faces.context.FacesContext context,
                                                     java.lang.String image,
                                                     int width,
                                                     int height,
                                                     java.lang.String alt,
                                                     java.lang.String onclick,
                                                     java.lang.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 java.lang.String buildImageTag​(javax.faces.context.FacesContext context,
                                                     java.lang.String image,
                                                     int width,
                                                     int height,
                                                     java.lang.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 java.lang.String buildImageTag​(javax.faces.context.FacesContext context,
                                                     java.lang.String image,
                                                     java.lang.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 java.lang.String buildImageTag​(javax.faces.context.FacesContext context,
                                                     java.lang.String image,
                                                     java.lang.String alt,
                                                     java.lang.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)