Class RenderKitUtils

java.lang.Object
com.sun.faces.renderkit.RenderKitUtils

public class RenderKitUtils extends Object

A set of utilities for use in RenderKits.

  • Field Details

    • LOGGER

      protected static final Logger LOGGER
    • DEVELOPMENT_STAGE_MESSAGES_ID

      public static final String DEVELOPMENT_STAGE_MESSAGES_ID
      See Also:
  • Method Details

    • getCurrentRenderKit

      public static RenderKit getCurrentRenderKit(FacesContext context)

      Return the RenderKit for the current request.

      Parameters:
      context - the FacesContext of the current request
      Returns:
      the RenderKit for the current request.
    • getResponseStateManager

      public static ResponseStateManager getResponseStateManager(FacesContext context, String renderKitId) throws FacesException

      Obtain and return the ResponseStateManager for the specified #renderKitId.

      Parameters:
      context - the FacesContext of the current request
      renderKitId - RenderKit ID
      Returns:
      the ResponseStateManager for the specified #renderKitId
      Throws:
      FacesException - if an exception occurs while trying to obtain the ResponseStateManager
    • getSelectItems

      public static SelectItemsIterator<SelectItem> getSelectItems(FacesContext context, UIComponent component)

      Return a List of SelectItem instances representing the available options for this component, assembled from the set of UISelectItem and/or UISelectItems components that are direct children of this component. If there are no such children, an empty Iterator is returned.

      Parameters:
      context - The FacesContext for the current request. If null, the UISelectItems behavior will not work.
      component - the component
      Returns:
      a List of the select items for the specified component
      Throws:
      IllegalArgumentException - if context is null
    • renderPassThruAttributes

      public static void renderPassThruAttributes(FacesContext context, ResponseWriter writer, UIComponent component, Attribute[] attributes) throws IOException

      Render any "passthru" attributes, where we simply just output the raw name and value of the attribute. This method is aware of the set of HTML4 attributes that fall into this bucket. Examples are all the javascript attributes, alt, rows, cols, etc.

      Parameters:
      context - the FacesContext for this request
      writer - writer the ResponseWriter to be used when writing the attributes
      component - the component
      attributes - an array of attributes to be processed
      Throws:
      IOException - if an error occurs writing the attributes
    • renderPassThruAttributes

      public static void renderPassThruAttributes(FacesContext context, ResponseWriter writer, UIComponent component, Attribute[] attributes, Map<String,List<ClientBehavior>> behaviors) throws IOException

      Render any "passthru" attributes, where we simply just output the raw name and value of the attribute. This method is aware of the set of HTML4 attributes that fall into this bucket. Examples are all the javascript attributes, alt, rows, cols, etc.

      Parameters:
      context - the FacesContext for this request
      writer - writer the ResponseWriter to be used when writing the attributes
      component - the component
      attributes - an array of attributes to be processed
      behaviors - the behaviors for this component, or null if component is not a ClientBehaviorHolder
      Throws:
      IOException - if an error occurs writing the attributes
    • renderOnchange

      public static void renderOnchange(FacesContext context, UIComponent component, boolean incExec) throws IOException
      Throws:
      IOException
    • renderSelectOnclick

      public static void renderSelectOnclick(FacesContext context, UIComponent component, boolean incExec) throws IOException
      Throws:
      IOException
    • renderOnclick

      public static void renderOnclick(FacesContext context, UIComponent component, Collection<ClientBehaviorContext.Parameter> params, String submitTarget, boolean needsSubmit) throws IOException
      Throws:
      IOException
    • renderFunction

      public static void renderFunction(FacesContext context, UIComponent component, Collection<ClientBehaviorContext.Parameter> params, String submitTarget) throws IOException
      Throws:
      IOException
    • prefixAttribute

      public static String prefixAttribute(String attrName, ResponseWriter writer)
    • prefixAttribute

      public static String prefixAttribute(String attrName, boolean isXhtml)
    • renderXHTMLStyleBooleanAttributes

      public static void renderXHTMLStyleBooleanAttributes(ResponseWriter writer, UIComponent component) throws IOException

      Renders the attributes from BOOLEAN_ATTRIBUTES using XHMTL semantics (i.e., disabled="disabled").

      Parameters:
      writer - writer the ResponseWriter to be used when writing the attributes
      component - the component
      Throws:
      IOException - if an error occurs writing the attributes
    • renderXHTMLStyleBooleanAttributes

      public static void renderXHTMLStyleBooleanAttributes(ResponseWriter writer, UIComponent component, List<String> excludedAttributes) throws IOException

      Renders the attributes from BOOLEAN_ATTRIBUTES using XHMTL semantics (i.e., disabled="disabled").

      Parameters:
      writer - writer the ResponseWriter to be used when writing the attributes
      component - the component
      excludedAttributes - a List of attributes that are to be excluded from rendering
      Throws:
      IOException - if an error occurs writing the attributes
    • determineContentType

      public static String determineContentType(String accept, String serverSupportedTypes, String preferredType)

      Given an accept String from the client, and a String of server supported content types, determine the best qualified content type for the client. If no match is found, or either of the arguments are null, null is returned.

      Parameters:
      accept - The client accept String
      serverSupportedTypes - The types that the server supports
      preferredType - The preferred content type if another type is found with the same highest quality factor.
      Returns:
      The content type String
    • isXml

      public static boolean isXml(String contentType)
      Parameters:
      contentType - the content type in question
      Returns:
      true if the content type is a known XML-based content type, otherwise, false
    • createValidECMAIdentifier

      public static String createValidECMAIdentifier(String origIdentifier)

      Replaces all occurrences of - with $_.

      Parameters:
      origIdentifier - the original identifer that needs to be 'ECMA-ized'
      Returns:
      an ECMA valid identifer
    • installFacesJsIfNecessary

      public static void installFacesJsIfNecessary(FacesContext context)

      Only install the Faces script resource if it doesn't exist. The resource component will be installed with the target "head".

      Parameters:
      context - the FacesContext for the current request
    • renderFacesJsIfNecessary

      public static void renderFacesJsIfNecessary(FacesContext context) throws IOException

      Renders the Javascript necessary to add and remove request parameters to the current form.

      Parameters:
      context - the FacesContext for the current request
      Throws:
      IOException - if an error occurs writing to the response
    • isFacesJsInstalled

      public static boolean isFacesJsInstalled(FacesContext context)
    • renderUnhandledMessages

      public static void renderUnhandledMessages(FacesContext ctx)
    • renderHtmlErrorPage

      public static void renderHtmlErrorPage(FacesContext ctx, FacesException fe)
    • isPartialOrBehaviorAction

      public static boolean isPartialOrBehaviorAction(FacesContext context, String clientId)
    • getFormClientId

      public static String getFormClientId(UIComponent component, FacesContext context)

      Utility method to return the client ID of the parent form.

      Parameters:
      component - typically a command component
      context - the FacesContext for the current request
      Returns:
      the client ID of the parent form, if any
    • getForm

      public static UIForm getForm(UIComponent component, FacesContext context)

      Utility method to return the client ID of the parent form.

      Parameters:
      component - typically a command component
      context - the FacesContext for the current request
      Returns:
      the parent form, if any
    • getImageSource

      public static String getImageSource(FacesContext context, UIComponent component, String attrName)

      Determine the path value of an image value for a component such as UIGraphic or UICommand.

      Parameters:
      context - the FacesContext for the current request.
      component - the component to obtain the image information from
      attrName - the attribute name that needs to be queried if the name and library attributes are not specified
      Returns:
      the encoded path to the image source
    • getParameterName

      public static String getParameterName(FacesContext context, String name)
      If view root is instance of naming container, prepend its container client id to namespace given parameter name.
      Parameters:
      context - Involved faces context.
      name - Request parameter name.
      Returns:
      The request parameter name, if necessary namespaced.
    • isOutputHtml5Doctype

      public static boolean isOutputHtml5Doctype(FacesContext context)
      Returns true if the view root associated with the given faces context will be rendered with a HTML5 doctype.
      Parameters:
      context - Involved faces context.
      Returns:
      true if the view root associated with the given faces context will be rendered with a HTML5 doctype.
    • appendProperty

      public static void appendProperty(StringBuilder builder, String name, Object value)
    • appendProperty

      public static void appendProperty(StringBuilder builder, String name, Object value, boolean quoteValue)
    • appendQuotedValue

      public static void appendQuotedValue(StringBuilder builder, String script)