org.ajax4jsf.renderkit
Class RendererUtils

java.lang.Object
  extended by org.ajax4jsf.renderkit.RendererUtils

public class RendererUtils
extends java.lang.Object

Util class for common render operations - render passthru html attributes, iterate over child components etc.

Version:
$Revision: 1.1.2.6 $ $Date: 2007/02/08 19:07:16 $
Author:
asmirnov@exadel.com (latest modification by $Author: alexsmirnov $)

Nested Class Summary
static interface RendererUtils.HTML
          Common HTML elements and attributes names.
static class RendererUtils.ScriptHashVariableWrapper
          Wrapper class around object value used to transform values into particular JS objects
 
Field Summary
static java.lang.String DUMMY_FORM_ID
           
 
Constructor Summary
protected RendererUtils()
           
 
Method Summary
 void addToScriptHash(java.util.Map<java.lang.String,java.lang.Object> hash, java.lang.String name, java.lang.Object value)
          Puts value into map under specified key if the value is not empty and not default.
 void addToScriptHash(java.util.Map<java.lang.String,java.lang.Object> hash, java.lang.String name, java.lang.Object value, java.lang.String defaultValue)
          Puts value into map under specified key if the value is not empty and not default.
 void addToScriptHash(java.util.Map<java.lang.String,java.lang.Object> hash, java.lang.String name, java.lang.Object value, java.lang.String defaultValue, RendererUtils.ScriptHashVariableWrapper wrapper)
          Puts value into map under specified key if the value is not empty and not default.
protected  java.lang.Object attributeValue(java.lang.String name, java.lang.Object value)
          Convert attribute value to proper object.
 java.lang.String clientId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Simplified version of encodeId
 java.lang.String correctForIdReference(java.lang.String forAttr, javax.faces.component.UIComponent component)
          If target component contains generated id and for doesn't, correct for id
 void encodeAttribute(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object property, java.lang.String attributeName)
           
 void encodeAttribute(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String attribute)
           
 void encodeAttributes(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String attrs)
          Encode attributes given by comma-separated string list.
 void encodeAttributesFromArray(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String[] attrs)
           
 void encodeBeginForm(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, javax.faces.context.ResponseWriter writer, java.lang.String clientId)
           
 void encodeBeginFormIfNessesary(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
           
 void encodeCustomId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Encode id attribute with clientId component property.
 void encodeDimensions(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, org.ajax4jsf.resource.InternetResource resource)
           
 void encodeEndForm(javax.faces.context.FacesContext context, javax.faces.context.ResponseWriter writer)
           
 void encodeEndFormIfNessesary(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
           
 void encodeId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Encode id attribute with clientId component property
 void encodeId(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String attribute)
          Encode clientId to custom attribute ( for example, to control name )
 void encodePassThru(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Encode common pass-thru html attributes.
 void encodePassThruAttribute(javax.faces.context.FacesContext context, java.util.Map<java.lang.String,java.lang.Object> attributes, javax.faces.context.ResponseWriter writer, java.lang.String attribute)
          Encode one pass-thru attribute, with plain/boolean/url value, got from properly component attribute.
 void encodePassThruWithExclusions(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String exclusions)
          Encode pass-through attributes except specified ones
 void encodePassThruWithExclusionsArray(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object[] exclusions)
           
 java.lang.String encodePctOrPx(java.lang.String value)
          formats given value to
 java.lang.String encodePx(java.lang.String value)
           
 java.lang.String encodeResourceURL(TemplateContext context, java.lang.Object value)
           
 java.lang.String escapeJavaScript(java.lang.Object o)
           
 javax.faces.component.UIComponent findComponentFor(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String id)
           
 javax.faces.component.UIComponent findComponentFor(javax.faces.component.UIComponent component, java.lang.String id)
           
 java.lang.String formatValue(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object value)
          Convert any object value to string.
 java.lang.String getActionUrl(javax.faces.context.FacesContext facesContext)
           
 org.ajax4jsf.javascript.JSFunctionDefinition getAsEventHandler(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String attributeName, java.lang.String append)
           
protected  java.lang.Object getComponentAttributeName(java.lang.Object key)
          Convert HTML attribute name to component property name.
static RendererUtils getInstance()
          Use this method to get singleton instance of RendererUtils
 javax.faces.component.UIForm getNestingForm(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Find nested form for given component
 java.lang.String getValueAsString(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component)
          Return converted value for ValueHolder as String, perform nessesary convertions.
 boolean isBooleanAttribute(javax.faces.component.UIComponent component, java.lang.String name)
          Get boolean value of logical attribute
 boolean isEmpty(java.lang.Object o)
          Checks if the argument passed in is empty or not.
 boolean isValidProperty(java.lang.Object property)
          Test for valid value of property.
 boolean shouldRenderAttribute(java.lang.Object attributeVal)
           
 boolean shouldRenderAttribute(java.lang.String attributeName, java.lang.Object attributeVal)
           
 void writeAttribute(javax.faces.context.ResponseWriter writer, java.lang.String attribute, java.lang.Object value)
          Write html-attribute
static void writeEventHandlerFunction(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.String eventName)
           
 void writeScript(javax.faces.context.FacesContext context, javax.faces.component.UIComponent component, java.lang.Object script)
          Wtrie JavaScript with start/end elements and type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DUMMY_FORM_ID

public static final java.lang.String DUMMY_FORM_ID
See Also:
Constant Field Values
Constructor Detail

RendererUtils

protected RendererUtils()
Method Detail

getInstance

public static RendererUtils getInstance()
Use this method to get singleton instance of RendererUtils

Returns:
singleton instance

encodeId

public void encodeId(javax.faces.context.FacesContext context,
                     javax.faces.component.UIComponent component)
              throws java.io.IOException
Encode id attribute with clientId component property

Parameters:
context -
component -
Throws:
java.io.IOException

encodeId

public void encodeId(javax.faces.context.FacesContext context,
                     javax.faces.component.UIComponent component,
                     java.lang.String attribute)
              throws java.io.IOException
Encode clientId to custom attribute ( for example, to control name )

Parameters:
context -
component -
attribute -
Throws:
java.io.IOException

encodeCustomId

public void encodeCustomId(javax.faces.context.FacesContext context,
                           javax.faces.component.UIComponent component)
                    throws java.io.IOException
Encode id attribute with clientId component property. Encoded only if id not auto generated.

Parameters:
context -
component -
Throws:
java.io.IOException

encodePassThru

public void encodePassThru(javax.faces.context.FacesContext context,
                           javax.faces.component.UIComponent component)
                    throws java.io.IOException
Encode common pass-thru html attributes.

Parameters:
context -
component -
Throws:
java.io.IOException

encodePassThruWithExclusions

public void encodePassThruWithExclusions(javax.faces.context.FacesContext context,
                                         javax.faces.component.UIComponent component,
                                         java.lang.String exclusions)
                                  throws java.io.IOException
Encode pass-through attributes except specified ones

Parameters:
context -
component -
exclusions -
Throws:
java.io.IOException

encodePassThruWithExclusionsArray

public void encodePassThruWithExclusionsArray(javax.faces.context.FacesContext context,
                                              javax.faces.component.UIComponent component,
                                              java.lang.Object[] exclusions)
                                       throws java.io.IOException
Throws:
java.io.IOException

encodePassThruAttribute

public void encodePassThruAttribute(javax.faces.context.FacesContext context,
                                    java.util.Map<java.lang.String,java.lang.Object> attributes,
                                    javax.faces.context.ResponseWriter writer,
                                    java.lang.String attribute)
                             throws java.io.IOException
Encode one pass-thru attribute, with plain/boolean/url value, got from properly component attribute.

Parameters:
context -
component -
writer -
attribute -
Throws:
java.io.IOException

encodeAttributesFromArray

public void encodeAttributesFromArray(javax.faces.context.FacesContext context,
                                      javax.faces.component.UIComponent component,
                                      java.lang.String[] attrs)
                               throws java.io.IOException
Throws:
java.io.IOException

encodeAttributes

public void encodeAttributes(javax.faces.context.FacesContext context,
                             javax.faces.component.UIComponent component,
                             java.lang.String attrs)
                      throws java.io.IOException
Encode attributes given by comma-separated string list.

Parameters:
context - current JSF context
component - for with render attributes values
attrs - comma separated list of attributes
Throws:
java.io.IOException

encodeAttribute

public void encodeAttribute(javax.faces.context.FacesContext context,
                            javax.faces.component.UIComponent component,
                            java.lang.Object property,
                            java.lang.String attributeName)
                     throws java.io.IOException
Parameters:
context -
component -
string -
string2 -
Throws:
java.io.IOException

encodeAttribute

public void encodeAttribute(javax.faces.context.FacesContext context,
                            javax.faces.component.UIComponent component,
                            java.lang.String attribute)
                     throws java.io.IOException
Throws:
java.io.IOException

writeAttribute

public void writeAttribute(javax.faces.context.ResponseWriter writer,
                           java.lang.String attribute,
                           java.lang.Object value)
                    throws java.io.IOException
Write html-attribute

Parameters:
writer -
attribute -
value -
Throws:
java.io.IOException

shouldRenderAttribute

public boolean shouldRenderAttribute(java.lang.Object attributeVal)
Returns:
true if and only if the argument attributeVal is an instance of a wrapper for a primitive type and its value is equal to the default value for that type as given in the spec.

shouldRenderAttribute

public boolean shouldRenderAttribute(java.lang.String attributeName,
                                     java.lang.Object attributeVal)

isValidProperty

public boolean isValidProperty(java.lang.Object property)
Test for valid value of property. by default, for non-setted properties with Java primitive types of JSF component return appropriate MIN_VALUE .

Parameters:
property - - value of property returned from UIComponent.getAttributes()
Returns:
true for setted property, false otherthise.

isEmpty

public boolean isEmpty(java.lang.Object o)
Checks if the argument passed in is empty or not. Object is empty if it is:
- null
- zero-length string
- empty collection
- empty map
- zero-length array

Parameters:
o - object to check for emptiness
Returns:
true if the argument is empty, false otherwise
Since:
3.3.2

addToScriptHash

public void addToScriptHash(java.util.Map<java.lang.String,java.lang.Object> hash,
                            java.lang.String name,
                            java.lang.Object value,
                            java.lang.String defaultValue,
                            RendererUtils.ScriptHashVariableWrapper wrapper)
Puts value into map under specified key if the value is not empty and not default. Performs optional value wrapping.

Parameters:
hash -
name -
value -
defaultValue -
wrapper -
Since:
3.3.2

addToScriptHash

public void addToScriptHash(java.util.Map<java.lang.String,java.lang.Object> hash,
                            java.lang.String name,
                            java.lang.Object value,
                            java.lang.String defaultValue)
Puts value into map under specified key if the value is not empty and not default. Performs optional value wrapping.

Parameters:
hash -
name -
value -
defaultValue -
Since:
3.3.2

addToScriptHash

public void addToScriptHash(java.util.Map<java.lang.String,java.lang.Object> hash,
                            java.lang.String name,
                            java.lang.Object value)
Puts value into map under specified key if the value is not empty and not default. Performs optional value wrapping.

Parameters:
hash -
name -
value -
Since:
3.3.2

getComponentAttributeName

protected java.lang.Object getComponentAttributeName(java.lang.Object key)
Convert HTML attribute name to component property name.

Parameters:
key -
Returns:

attributeValue

protected java.lang.Object attributeValue(java.lang.String name,
                                          java.lang.Object value)
Convert attribute value to proper object. For known html boolean attributes return name for true value, otherthise - null. For non-boolean attributes return same value.

Parameters:
name - attribute name.
value -
Returns:

isBooleanAttribute

public boolean isBooleanAttribute(javax.faces.component.UIComponent component,
                                  java.lang.String name)
Get boolean value of logical attribute

Parameters:
component -
name - attribute name
Returns:
true if attribute is equals Boolean.TRUE or String "true" , false otherwise.

getValueAsString

public java.lang.String getValueAsString(javax.faces.context.FacesContext context,
                                         javax.faces.component.UIComponent component)
Return converted value for ValueHolder as String, perform nessesary convertions.

Parameters:
context -
component -
Returns:

formatValue

public java.lang.String formatValue(javax.faces.context.FacesContext context,
                                    javax.faces.component.UIComponent component,
                                    java.lang.Object value)
Convert any object value to string. If component instance of ValueHolder got Converter for formatting. If not, attempt to use converter based on value type.

Parameters:
context -
component -
Returns:

encodeDimensions

public void encodeDimensions(javax.faces.context.FacesContext context,
                             javax.faces.component.UIComponent component,
                             org.ajax4jsf.resource.InternetResource resource)
                      throws java.io.IOException
Throws:
java.io.IOException

encodePx

public java.lang.String encodePx(java.lang.String value)

encodePctOrPx

public java.lang.String encodePctOrPx(java.lang.String value)
formats given value to

Parameters:
value -
pattern -
Returns:

getNestingForm

public javax.faces.component.UIForm getNestingForm(javax.faces.context.FacesContext context,
                                                   javax.faces.component.UIComponent component)
Find nested form for given component

Parameters:
component -
Returns:
nested UIForm component, or null

encodeBeginFormIfNessesary

public void encodeBeginFormIfNessesary(javax.faces.context.FacesContext context,
                                       javax.faces.component.UIComponent component)
                                throws java.io.IOException
Parameters:
context -
component -
Throws:
java.io.IOException

encodeBeginForm

public void encodeBeginForm(javax.faces.context.FacesContext context,
                            javax.faces.component.UIComponent component,
                            javax.faces.context.ResponseWriter writer,
                            java.lang.String clientId)
                     throws java.io.IOException
Parameters:
context -
component -
writer -
clientId -
Throws:
java.io.IOException

encodeEndFormIfNessesary

public void encodeEndFormIfNessesary(javax.faces.context.FacesContext context,
                                     javax.faces.component.UIComponent component)
                              throws java.io.IOException
Parameters:
context -
component -
Throws:
java.io.IOException

encodeEndForm

public void encodeEndForm(javax.faces.context.FacesContext context,
                          javax.faces.context.ResponseWriter writer)
                   throws java.io.IOException
Parameters:
context -
writer -
Throws:
java.io.IOException

getActionUrl

public java.lang.String getActionUrl(javax.faces.context.FacesContext facesContext)
Parameters:
facesContext -
Returns:
String A String representing the action URL

encodeResourceURL

public java.lang.String encodeResourceURL(TemplateContext context,
                                          java.lang.Object value)
Parameters:
context -
value -
Returns:
URL of target resource (src, href, etc)

clientId

public java.lang.String clientId(javax.faces.context.FacesContext context,
                                 javax.faces.component.UIComponent component)
Simplified version of encodeId

Parameters:
context -
component -
Returns:
client id of current component

writeScript

public void writeScript(javax.faces.context.FacesContext context,
                        javax.faces.component.UIComponent component,
                        java.lang.Object script)
                 throws java.io.IOException
Wtrie JavaScript with start/end elements and type.

Parameters:
context -
tab -
string -
Throws:
java.io.IOException

findComponentFor

public javax.faces.component.UIComponent findComponentFor(javax.faces.context.FacesContext context,
                                                          javax.faces.component.UIComponent component,
                                                          java.lang.String id)

findComponentFor

public javax.faces.component.UIComponent findComponentFor(javax.faces.component.UIComponent component,
                                                          java.lang.String id)
Parameters:
component -
id -
Returns:

correctForIdReference

public java.lang.String correctForIdReference(java.lang.String forAttr,
                                              javax.faces.component.UIComponent component)
If target component contains generated id and for doesn't, correct for id

Parameters:
forAttr -
target -

writeEventHandlerFunction

public static void writeEventHandlerFunction(javax.faces.context.FacesContext context,
                                             javax.faces.component.UIComponent component,
                                             java.lang.String eventName)
                                      throws java.io.IOException
Throws:
java.io.IOException

getAsEventHandler

public org.ajax4jsf.javascript.JSFunctionDefinition getAsEventHandler(javax.faces.context.FacesContext context,
                                                                      javax.faces.component.UIComponent component,
                                                                      java.lang.String attributeName,
                                                                      java.lang.String append)

escapeJavaScript

public java.lang.String escapeJavaScript(java.lang.Object o)


Copyright © 2009. All Rights Reserved.