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

Description

The <o:form> extends the standard <h:form> and provides support for including all view parameters in the URL that's used for the post-back, or all request parameters, or the entire original request URI.

By setting the includeViewParams attribute to true (default is false), the current value of every view parameter will be added to the action URL that will be rendered on the form. This is similar to how the attribute of the same name can be used on the <h:link> and <h:button> components.

In case all URL (GET) parameters are needed, the includeRequestParams attribute can be set to true (default is false). This setting will override includeViewParams.

In case the entire original request URI, including the URL (GET) parameters, is needed, the useRequestURI attribute can be set to true (default is false). This setting will override includeViewParams and includeRequestParams.

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 post back the "includeViewParams form" 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 id="test" name="test" value="#{viewParamBean.test}" />
</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="test" value="foo" />
    </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" action="#{viewParamBean.action}" />
</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="test" value="000" />
        <f:param name="foo" value="123" />
        <f:param name="foo" value="456" />
        <f:param name="bar" 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 post back the "includeViewParams form" to see that only the view 
    param will be preserved)
</p>
<o:form includeRequestParams="true">
    <h:commandLink value="POST-BACK o:form with includeRequestParams" action="#{viewParamBean.action}" />
</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" action="#{viewParamBean.action}" />
</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" action="#{viewParamBean.action}" />
</h:form>

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