The <o:url> is a component which renders the given target URL or Faces view ID as a bookmarkable URL with support for adding additional
query string parameters to the URL via nested <f:param> and <o:param>, and for exposing it into the request scope by
the variable name as specified by the var attribute instead of rendering it.
This component fills the gap caused by absence of JSTL <c:url> in Facelets. This component is useful for generating URLs for usage in e.g.
plain HTML <link> elements and JavaScript variables.
You can supply the target URL via either the value attribute or the viewId attribute. When both are specified, the
value attribute takes precedence and the viewId attribute is ignored. When none are specified, then the viewId will
default to the current view ID. The support for value attribute was added in OmniFaces 3.0.
When the target URL is specified as viewId, then the domain of the target URL defaults to the current domain. It is possible to provide a full
qualified domain name (FQDN) via the domain attribute which the URL is to be prefixed with. This can be useful if a canonical page shall point
to a different domain or a specific subdomain.
Valid formats and values for domain attribute are:
<o:url domain="https://example.com" /><o:url domain="//example.com" /><o:url domain="example.com" /><o:url domain="/" /><o:url domain="//" />
The domain value will be validated by URL and throw an illegal argument exception when invalid. If the domain equals /,
then the URL becomes domain-relative. If the domain equals or starts with //, or does not contain any scheme, then the URL becomes
scheme-relative. If the value attribute is specified, then the domain attribute is ignored.
You can add query string parameters to the URL via nested <f:param> and <o:param>. You can optionally include all GET
request query string parameters or only Faces view parameters in the resulting URL via includeRequestParams="true" or
includeViewParams="true". The includeViewParams is ignored when includeRequestParams="true". The
<f|o:param> will override any included request or view parameters on the same name. To conditionally add or override, use the
disabled attribute of <f|o:param>.
Some examples:
<p>Full URL of current page is: <o:url /></p>
<p>Full URL of another page is: <o:url viewId="/another.xhtml" /></p>
<p>Full URL of current page including view params is: <o:url includeViewParams="true" /></p>
<p>Full URL of current page including query string is: <o:url includeRequestParams="true" /></p>
<p>Domain-relative URL of current page is: <o:url domain="/" /></p>
<p>Scheme-relative URL of current page is: <o:url domain="//" /></p>
<p>Scheme-relative URL of current page on a different domain is: <o:url domain="sub.example.com" /></p>
<p>Full URL of current page on a different domain is: <o:url domain="https://sub.example.com" /></p>
<p>External URL with encoded parameters appended: <o:url value="https://google.com/search">
<o:param name="q" value="#{bean.search}" />
</url></p>
<o:url var="_linkCanonical">
<o:param name="foo" value="#{bean.foo}" />
</o:url>
<link rel="canonical" href="#{_linkCanonical}" />
<o:url var="_linkNext" includeViewParams="true">
<f:param name="page" value="#{bean.pageIndex + 1}" />
</o:url>
<link rel="next" href="#{_linkNext}" />
| Info | Value |
|---|---|
| Component Type | org.omnifaces.component.output.Url |
| Handler Class | None |
| Renderer Type | None |
| Description | None |
| Name | Required | Type | Description |
|---|---|---|---|
binding | false | jakarta.el.ValueExpression
(must evaluate to jakarta.faces.component.UIComponent)
| The ValueExpression linking this component to a property in a backing bean. |
domain | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| The domain of the URL. Defaults to current domain. |
id | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| The component identifier for this component. This value must be unique within the closest parent component that is a naming container. |
includeRequestParams | false | jakarta.el.ValueExpression
(must evaluate to boolean)
| Whether or not the request query string parameters should be encoded into the URL. Defaults to false. When set to true, then this
will override the includeViewParams setting. |
includeViewParams | false | jakarta.el.ValueExpression
(must evaluate to boolean)
| Whether or not the view parameters should be encoded into the URL. Defaults to false. This setting is ignored when
includeRequestParams is set to true. |
rendered | false | jakarta.el.ValueExpression
(must evaluate to boolean)
| Flag indicating whether or not this component should be rendered (during Render Response Phase), or processed on any subsequent form submit. The default value for this property is true. |
value | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| The target URL to encode. When specified, the domain and viewId attributes are ignored. |
var | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| The variable name which exposes the URL into the request scope. |
viewId | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| The view ID to create URL for. Defaults to current view ID. This is ignored when value attribute is specified. |
Output generated by Vdldoc View Declaration Language Documentation Generator.