• cdi
  • components
  • contexts
  • converters
  • eventlisteners
  • exceptionhandlers
  • facesviews
  • filters
  • functions
  • managedbeans
  • renderkits
  • resourcehandlers
  • scripts
  • taghandlers
  • utils
  • validators
  • viewhandlers
-
  • cache
  • commandScript
  • componentIdParam
  • conditionalComment
  • deferredScript
  • form
  • graphicImage
  • highlight
  • messages
  • moveComponent
  • onloadScript
  • outputFormat
  • outputLabel
  • param
  • resolveComponent
  • resourceInclude
  • tree
  • viewParam

The <o:form> is a component that extends the standard <h:form> and provides a way to keep view or request parameters in the request URL after a post-back and offers in combination with the <o:ignoreValidationFailed> tag on an UICommand component the possibility to ignore validation failures so that the invoke action phase will be executed anyway.

You can use it the same way as <h:form>, you only need to change h: to o:.

Include View Params

The standard UIForm doesn't put the original view parameters in the action URL that's used for the post-back. Instead, it relies on those view parameters to be stored in the state associated with the standard UIViewParameter. Via this state those parameters are invisibly re-applied after every post-back.

The disadvantage of this invisible retention of view parameters is that the user doesn't see them anymore in the address bar of the browser that is used to interact with the faces application. Copy-pasting the URL from the address bar or refreshing the page by hitting enter inside the address bar will therefore not always yield the expected results.

To solve this, this component offers an attribute includeViewParams="true" that will optionally include all view parameters, in exactly the same way that this can be done for <h:link> and <h:button>.

This setting is ignored when includeRequestParams="true" or useRequestURI="true" is used.

Include Request Params

As an alternative to includeViewParams, you can use includeRequestParams="true" to optionally include the current GET request query string.

This setting overrides the includeViewParams. This setting is ignored when useRequestURI="true" is used.

Use request URI

As an alternative to includeViewParams and includeRequestParams, you can use useRequestURI="true" to use the current request URI, including with the GET request query string, if any. This is particularly useful if you're using FacesViews or forwarding everything to 1 page. Otherwise, by default the current view ID will be used.

This setting overrides the includeViewParams and includeRequestParams.

Ignore Validation Failed

In order to properly use the <o:ignoreValidationFailed> tag on an UICommand component, its parent <h:form> component has to be replaced by this <o:form> component. See also IgnoreValidationFailed.

Demo

First do a GET request to the current page to start using a view parameter.

Do GET request with view param

Then, do one or more POSTs in an o:form to see that the GET parameter that's been used as a view parameter in the URL is preserved.

POST-BACK o:form with includeViewParams

Now do a GET request to the current page to additionally start using GET parameters which are NOT also view parameters.

Do GET request with a view param and free GET parameters

Then, do one or more POSTs in an o:form with includeRequestParams to see that all the GET parameters are being preserverd in the URL (try to click "POST-BACK o:form with includeViewParams" to see that only the view param will be preserved).

POST-BACK o:form with includeRequestParams

Then, do one or more POSTs in an o:form with useRequestURI to see that the entire request URI, including GET parameters, is being preserverd in the URL.

POST-BACK o:form with useRequestURI

Finally, do a POST via a standard JSF h:form to see that all the GET parameter in URL disappears.

POST-BACK h:form

The value:

Source code
<f:metadata>
    <o:viewParam name="foo" value="#{viewParamBean.foo}" />
</f:metadata>

<p>
    First do a GET request to the current page to start using a view parameter.
</p>
<p>
    <h:link value="Do GET request with view param">
        <f:param name="foo" value="value" />
    </h:link>
</p>

<p>
    Then, do one or more POSTs in an o:form to see that the GET parameter that's been used as a 
    view parameter in the URL is preserved.
</p>
<o:form includeViewParams="true">
    <h:commandLink value="POST-BACK o:form with includeViewParams" />
</o:form>

<p>
    Now do a GET request to the current page to additionally start using GET parameters which are NOT 
    also view parameters.
</p>
<p>
    <h:link value="Do GET request with a view param and free GET parameters">
        <f:param name="foo" value="000" />
        <f:param name="bar" value="123" />
        <f:param name="bar" value="456" />
        <f:param name="baz" value="xxx" />
    </h:link>
</p>

<p>
    Then, do one or more POSTs in an o:form with includeRequestParams to see that all the GET parameters 
    are being preserverd in the URL (try to click "POST-BACK o:form with includeViewParams" to see that only the view 
    param will be preserved).
</p>
<o:form includeRequestParams="true">
    <h:commandLink value="POST-BACK o:form with includeRequestParams" />
</o:form>

<p>
    Then, do one or more POSTs in an o:form with useRequestURI to see that the entire request URI, including
    GET parameters, is being preserverd in the URL.
</p>
<o:form useRequestURI="true">
    <h:commandLink value="POST-BACK o:form with useRequestURI" />
</o:form>

<p>
    Finally, do a POST via a standard JSF h:form to see that all the GET parameter in URL disappears.
</p>
<h:form>
    <h:commandLink value="POST-BACK h:form" />
</h:form>

<p>
    <b>The value:</b> #{viewParamBean.foo}
</p>