org.omnifaces.component.output
Class OutputFormat

java.lang.Object
  extended by javax.faces.component.UIComponent
      extended by javax.faces.component.UIComponentBase
          extended by javax.faces.component.UIOutput
              extended by javax.faces.component.html.HtmlOutputFormat
                  extended by org.omnifaces.component.output.OutputFormat
All Implemented Interfaces:
java.util.EventListener, javax.faces.component.PartialStateHolder, javax.faces.component.StateHolder, javax.faces.component.ValueHolder, javax.faces.event.ComponentSystemEventListener, javax.faces.event.FacesListener, javax.faces.event.SystemEventListenerHolder

public class OutputFormat
extends javax.faces.component.html.HtmlOutputFormat

OutputFormat is a component that extends the standard HtmlOutputFormat and provides support for capturing the output and exposing it into the request scope by the variable name as specified by the var attribute.

You can use it the same way as <h:outputFormat>, you only need to change h: into o: to get the extra support for var attribute. Here's are some usage examples:

 <o:outputFormat value="#{i18n['link.title']}" var="_link_title">
     <f:param value="#{bean.foo}" />
     <f:param value="#{bean.bar}" />
 </o:outputFormat>
 <h:commandLink value="#{i18n['link.value']}" title="#{_link_title}" />
 
 <o:outputFormat value="#{bean.number}" var="_percentage">
     <f:convertNumber type="percent" />
 </o:outputFormat>
 <div title="Percentage: #{_percentage}" />
 

Make sure that the var attribute value doesn't conflict with any of existing variable names in the current EL scope, such as managed bean names. It would be a good naming convention to start their names with _.

Since:
1.2
Author:
Bauke Scholtz

Field Summary
static java.lang.String COMPONENT_TYPE
          The standard component type.
 
Fields inherited from class javax.faces.component.UIOutput
COMPONENT_FAMILY
 
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
 
Constructor Summary
OutputFormat()
           
 
Method Summary
 void encodeBegin(javax.faces.context.FacesContext context)
          If the var attribute is set, start capturing the output.
 void encodeEnd(javax.faces.context.FacesContext context)
          If the var attribute is set, stop capturing the output and expose it in request scope by the var attribute value as variable name.
 java.lang.String getVar()
          Returns the variable name which exposes the captured output into the request scope.
 void setValueExpression(java.lang.String name, javax.el.ValueExpression binding)
          An override which checks if this isn't been invoked on var attribute.
 void setVar(java.lang.String var)
          Sets the variable name which exposes the captured output into the request scope.
 
Methods inherited from class javax.faces.component.html.HtmlOutputFormat
getDir, getLang, getStyle, getStyleClass, getTitle, isEscape, setDir, setEscape, setLang, setStyle, setStyleClass, setTitle
 
Methods inherited from class javax.faces.component.UIOutput
clearInitialState, getConverter, getFamily, getLocalValue, getValue, markInitialState, restoreState, saveState, setConverter, setValue
 
Methods inherited from class javax.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, 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, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, saveAttachedState, 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, 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 java.lang.String COMPONENT_TYPE
The standard component type.

See Also:
Constant Field Values
Constructor Detail

OutputFormat

public OutputFormat()
Method Detail

setValueExpression

public void setValueExpression(java.lang.String name,
                               javax.el.ValueExpression binding)
An override which checks if this isn't been invoked on var attribute. Finally it delegates to the super method.

Overrides:
setValueExpression in class javax.faces.component.UIComponent
Throws:
java.lang.IllegalArgumentException - When this value expression is been set on var attribute.

encodeBegin

public void encodeBegin(javax.faces.context.FacesContext context)
                 throws java.io.IOException
If the var attribute is set, start capturing the output.

Overrides:
encodeBegin in class javax.faces.component.UIComponentBase
Throws:
java.io.IOException

encodeEnd

public void encodeEnd(javax.faces.context.FacesContext context)
               throws java.io.IOException
If the var attribute is set, stop capturing the output and expose it in request scope by the var attribute value as variable name.

Overrides:
encodeEnd in class javax.faces.component.UIComponentBase
Throws:
java.io.IOException

getVar

public java.lang.String getVar()
Returns the variable name which exposes the captured output into the request scope.

Returns:
The variable name which exposes the captured output into the request scope.

setVar

public void setVar(java.lang.String var)
Sets the variable name which exposes the captured output into the request scope.

Parameters:
var - The variable name which exposes the captured output into the request scope.