Class OutputFormat

All Implemented Interfaces:
PartialStateHolder, StateHolder, TransientStateHolder, ValueHolder, ComponentSystemEventListener, FacesListener, SystemEventListenerHolder, EventListener

public class OutputFormat extends HtmlOutputFormat

The <o:outputFormat> is a component that extends the standard <h:outputFormat> with 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 Details

    • COMPONENT_TYPE

      public static final String COMPONENT_TYPE
      The component type, which is "org.omnifaces.component.output.OutputFormat".
      See Also:
  • Constructor Details

    • OutputFormat

      public OutputFormat()
  • Method Details

    • setValueExpression

      public void setValueExpression(String name, 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 HtmlOutputFormat
      Throws:
      IllegalArgumentException - When this value expression is been set on var attribute.
    • encodeBegin

      public void encodeBegin(FacesContext context) throws IOException
      If the var attribute is set, start capturing the output.
      Overrides:
      encodeBegin in class UIComponentBase
      Throws:
      IOException
    • encodeEnd

      public void encodeEnd(FacesContext context) throws 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 UIComponentBase
      Throws:
      IOException
    • getVar

      public 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(String varName)
      Sets the variable name which exposes the captured output into the request scope.
      Parameters:
      varName - The variable name which exposes the captured output into the request scope.