public class Url extends OutputFamily
The <o:url>
is a component which renders the given JSF view ID as a bookmarkable URL with support
for exposing it into the request scope by the variable name as specified by the var
attribute instead of
rendering it.
This component also supports adding query string parameters to the URL via nested <f:param>
and
<o:param>
. This can be used in combination with includeViewParams
and
includeRequestParams
. The <f|o:param>
will override any included view or request
parameters on the same name. To conditionally add or override, use the disabled
attribute of
<f|o:param>
.
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.
The domain of the 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="http://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 value equals /
, then the URL becomes domain-relative.
If the value equals or starts with //
, or does not contain any scheme, then the URL becomes scheme-relative.
You can optionally include all GET request query string parameters or only JSF 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.
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>
<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}" />
OutputFamily
Modifier and Type | Field and Description |
---|---|
static String |
COMPONENT_TYPE
The standard component type.
|
COMPONENT_FAMILY
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, CURRENT_COMPONENT, CURRENT_COMPOSITE_COMPONENT, FACETS_KEY, HONOR_CURRENT_COMPONENT_ATTRIBUTES_PARAM_NAME, VIEW_LOCATION_KEY
Constructor and Description |
---|
Url() |
Modifier and Type | Method and Description |
---|---|
void |
encodeEnd(FacesContext context) |
String |
getDomain()
Returns the domain of the URL.
|
boolean |
getRendersChildren()
Returns
false . |
String |
getVar()
Returns the variable name which exposes the URL into the request scope.
|
String |
getViewId()
Returns the view ID to create URL for.
|
boolean |
isIncludeRequestParams()
Returns whether or not the request query string parameters should be encoded into the URL.
|
boolean |
isIncludeViewParams()
Returns whether or not the view parameters should be encoded into the URL.
|
void |
setDomain(String domain)
Sets the domain of the URL.
|
void |
setIncludeRequestParams(boolean includeRequestParams)
Sets whether or not the request query string parameters should be encoded into the URL.
|
void |
setIncludeViewParams(boolean includeViewParams)
Sets whether or not the view parameters should be encoded into the URL.
|
void |
setValueExpression(String name,
ValueExpression binding)
An override which checks if this isn't been invoked on
var attribute. |
void |
setVar(String var)
Sets the variable name which exposes the URL into the request scope.
|
void |
setViewId(String viewId)
Sets the view ID to create URL for.
|
getFamily
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeBegin, encodeChildren, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEvent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, visitTree
public static final String COMPONENT_TYPE
public void setValueExpression(String name, ValueExpression binding)
var
attribute.
Finally it delegates to the super method.setValueExpression
in class UIComponent
IllegalArgumentException
- When this value expression is been set on var
attribute.public boolean getRendersChildren()
false
.getRendersChildren
in class OutputFamily
public void encodeEnd(FacesContext context) throws IOException
encodeEnd
in class UIComponentBase
IOException
public String getVar()
public void setVar(String var)
var
- The variable name which exposes the URL into the request scope.public String getDomain()
public void setDomain(String domain)
domain
- The domain of the URL.public String getViewId()
public void setViewId(String viewId)
viewId
- The view ID to create URL for.public boolean isIncludeViewParams()
false
.
This setting is ignored when includeRequestParams
is set to true
.public void setIncludeViewParams(boolean includeViewParams)
includeRequestParams
is set to true
.includeViewParams
- Whether or not the view parameters should be encoded into the URL.public boolean isIncludeRequestParams()
false
.
When set to true
, then this will override the includeViewParams
setting.public void setIncludeRequestParams(boolean includeRequestParams)
true
, then this will override the includeViewParams
setting.includeRequestParams
- Whether or not the request query string parameters should be encoded into the URL.Copyright © 2012–2018 OmniFaces. All rights reserved.