org.jboss.seam.faces.component
Class UIInputContainer

java.lang.Object
  extended by javax.faces.component.UIComponent
      extended by javax.faces.component.UIComponentBase
          extended by org.jboss.seam.faces.component.UIInputContainer
All Implemented Interfaces:
EventListener, NamingContainer, PartialStateHolder, StateHolder, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder

public class UIInputContainer
extends UIComponentBase
implements NamingContainer

UIInputContainer is a supplemental component for a JSF 2.0 composite component encapsulating one or more input components (EditableValueHolder), their corresponding message components (UIMessage) and a label (HtmlOutputLabel). This component takes care of wiring the label to the first input and the messages to each input in sequence. It also assigns two implicit attribute values, "required" and "invalid" to indicate that a required input field is present and whether there are any validation errors, respectively. To determine if a input field is required, both the required attribute is consulted. Finally, if the "label" attribute is not provided on the composite component, the label value will be derived from the id of the composite component, for convenience.

Composite component definition example (minus layout):

 <cc:interface componentType="org.jboss.seam.faces.InputContainer"/>
 <cc:implementation>
   <h:outputLabel id="label" value="#{cc.attrs.label}:" styleClass="#{cc.attrs.invalid ? 'invalid' : ''}">
     <h:ouputText styleClass="required" rendered="#{cc.attrs.required}" value="*"/>
   </h:outputLabel>
   <cc:insertChildren/>
   <h:message id="message" errorClass="invalid message" rendered="#{cc.attrs.invalid}"/>
 </cc:implementation>
 

Composite component usage example:

 <example:inputContainer id="name">
   <h:inputText id="input" value="#{person.name}"/>
 </example:inputContainer>
 

Possible enhancements:

NOTE: Firefox does not properly associate a label with the target input if the input id contains a colon (:), the default separator character in JSF. JSF 2 allows developers to set the value via an initialization parameter (context-param in web.xml) keyed to javax.faces.SEPARATOR_CHAR. We recommend that you override this setting to make the separator an underscore (_).

Author:
Dan Allen, Jose Rodolfo freitas

Nested Class Summary
static class UIInputContainer.InputContainerElements
           
 
Field Summary
static String COMPONENT_TYPE
          The standard component type for this component.
protected static String HTML_CLASS_ATTR_NAME
           
protected static String HTML_ID_ATTR_NAME
           
protected static String HTML_STYLE_ATTR_NAME
           
 
Fields inherited from class javax.faces.component.UIComponent
BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, VIEW_LOCATION_KEY
 
Fields inherited from interface javax.faces.component.NamingContainer
SEPARATOR_CHAR
 
Constructor Summary
UIInputContainer()
           
 
Method Summary
 void assignIds(UIInputContainer.InputContainerElements elements, FacesContext context)
           
 void encodeBegin(FacesContext context)
           
 void encodeEnd(FacesContext context)
           
protected  void endContainerElement(FacesContext context)
           
protected  String generateLabel(UIInputContainer.InputContainerElements elements, FacesContext context)
           
 String getContainerElementName()
           
 String getDefaultInputId()
           
 String getDefaultLabelId()
           
 String getDefaultMessageId()
           
 String getElementsAttributeName()
          The name of the auto-generated composite component attribute that holds the elements in this input container.
 String getEncloseAttributeName()
          The name of the composite component attribute that holds a boolean indicating whether the component template should be enclosed in an HTML element, so that it be referenced from JavaScript.
 String getFamily()
           
 String getInvalidAttributeName()
          The name of the auto-generated composite component attribute that holds a boolean indicating whether the the template contains an invalid input.
 String getLabelAttributeName()
          The name of the composite component attribute that holds the string label for this set of inputs.
 String getRequiredAttributeName()
          The name of the auto-generated composite component attribute that holds a boolean indicating whether the template contains a required input.
protected  UIInputContainer.InputContainerElements scan(UIComponent component, UIInputContainer.InputContainerElements elements, FacesContext context)
          Walk the component tree branch built by the composite component and locate the input container elements.
protected  void startContainerElement(FacesContext context)
           
protected  void wire(UIInputContainer.InputContainerElements elements, FacesContext context)
          Wire the label and messages to the input(s)
 
Methods inherited from class javax.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeChildren, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getRenderer, getRendererType, getRendersChildren, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding
 
Methods inherited from class javax.faces.component.UIComponent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getResourceBundleMap, getStateHelper, getStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, setInView, setValueExpression, subscribeToEvent, unsubscribeFromEvent, visitTree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPONENT_TYPE

public static final String COMPONENT_TYPE
The standard component type for this component.

See Also:
Constant Field Values

HTML_ID_ATTR_NAME

protected static final String HTML_ID_ATTR_NAME
See Also:
Constant Field Values

HTML_CLASS_ATTR_NAME

protected static final String HTML_CLASS_ATTR_NAME
See Also:
Constant Field Values

HTML_STYLE_ATTR_NAME

protected static final String HTML_STYLE_ATTR_NAME
See Also:
Constant Field Values
Constructor Detail

UIInputContainer

public UIInputContainer()
Method Detail

getFamily

public String getFamily()
Specified by:
getFamily in class UIComponent

getInvalidAttributeName

public String getInvalidAttributeName()
The name of the auto-generated composite component attribute that holds a boolean indicating whether the the template contains an invalid input.


getRequiredAttributeName

public String getRequiredAttributeName()
The name of the auto-generated composite component attribute that holds a boolean indicating whether the template contains a required input.


getLabelAttributeName

public String getLabelAttributeName()
The name of the composite component attribute that holds the string label for this set of inputs. If the label attribute is not provided, one will be generated from the id of the composite component or, if the id is defaulted, the name of the property bound to the first input.


getElementsAttributeName

public String getElementsAttributeName()
The name of the auto-generated composite component attribute that holds the elements in this input container. The elements include the label, a list of inputs and a cooresponding list of messages.


getEncloseAttributeName

public String getEncloseAttributeName()
The name of the composite component attribute that holds a boolean indicating whether the component template should be enclosed in an HTML element, so that it be referenced from JavaScript.


getContainerElementName

public String getContainerElementName()

getDefaultLabelId

public String getDefaultLabelId()

getDefaultInputId

public String getDefaultInputId()

getDefaultMessageId

public String getDefaultMessageId()

encodeBegin

public void encodeBegin(FacesContext context)
                 throws IOException
Overrides:
encodeBegin in class UIComponentBase
Throws:
IOException

encodeEnd

public void encodeEnd(FacesContext context)
               throws IOException
Overrides:
encodeEnd in class UIComponentBase
Throws:
IOException

startContainerElement

protected void startContainerElement(FacesContext context)
                              throws IOException
Throws:
IOException

endContainerElement

protected void endContainerElement(FacesContext context)
                            throws IOException
Throws:
IOException

generateLabel

protected String generateLabel(UIInputContainer.InputContainerElements elements,
                               FacesContext context)

scan

protected UIInputContainer.InputContainerElements scan(UIComponent component,
                                                       UIInputContainer.InputContainerElements elements,
                                                       FacesContext context)
Walk the component tree branch built by the composite component and locate the input container elements.

Returns:
a composite object of the input container elements

assignIds

public void assignIds(UIInputContainer.InputContainerElements elements,
                      FacesContext context)

wire

protected void wire(UIInputContainer.InputContainerElements elements,
                    FacesContext context)
Wire the label and messages to the input(s)



Copyright © 2011 Seam Framework. All Rights Reserved.