- All Implemented Interfaces:
PartialStateHolder,StateHolder,TransientStateHolder,ComponentSystemEventListener,FacesListener,SystemEventListenerHolder,EventListener
The <o:sitemapUrl> is a component which renders the given target URL or Faces view ID as a sitemap
URL with support for adding additional query string parameters to the URL via nested <f:param>
and <o:param>.
This component is largely based off the Url component behind <o:url>, but then tailored
specifically for usage in sitemap.xml file. The ViewResourceHandler must be registered in
faces-config.xml in order to get Faces components to run in /sitemap.xml.
Values
You can supply the sitemap 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.
Domain
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:sitemapUrl ... domain="https://example.com" /><o:sitemapUrl ... domain="//example.com" /><o:sitemapUrl ... domain="example.com" /><o:sitemapUrl ... domain="/" /><o:sitemapUrl ... 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.
Request parameters
You can add query string parameters to the URL via nested <f:param> and <o:param>.
To conditionally add or override, use the disabled attribute of <f|o:param>.
Usage
Usage example of /sitemap.xml as a Faces view:
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:ui="jakarta.faces.facelets"
xmlns:o="omnifaces"
>
<ui:repeat value="#{sitemapBean.products}" var="product">
<o:sitemapUrl viewId="/product.xhtml" lastModified="#{product.lastModified}" changeFrequency="weekly" priority="1.0">
<o:param name="id" value="#{product}" converter="productConverter" />
</o:sitemapUrl>
</ui:repeat>
</urlset>
- Since:
- 3.10
- Author:
- Bauke Scholtz
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe available values of the "changefreq" element of the sitemap URL. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe component type, which is "org.omnifaces.component.output.SitemapUrl".Fields inherited from class org.omnifaces.component.output.OutputFamily
COMPONENT_FAMILYFields inherited from class jakarta.faces.component.UIComponent
ATTRS_WITH_DECLARED_DEFAULT_VALUES, BEANINFO_KEY, bindings, COMPOSITE_COMPONENT_TYPE_KEY, COMPOSITE_FACET_NAME, FACETS_KEY, VIEW_LOCATION_KEY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidencodeBegin(FacesContext context) Renders the start of the<url>parent element.protected voidencodeChangeFrequency(FacesContext context) Renders the<changefreq>child element with the value ofgetChangeFrequency(), if any.voidencodeChildren(FacesContext context) Delegates toencodeLocation(FacesContext),encodeLastModified(FacesContext),encodeChangeFrequency(FacesContext)andencodePriority(FacesContext)in this order.voidencodeEnd(FacesContext context) Renders the end of the<url>parent element.protected voidencodeLastModified(FacesContext context) Renders the<lastmod>child element with the value ofgetLastModified(), if any.protected voidencodeLocation(FacesContext context) Renders the<loc>child element with either the value ofgetValue(), or the value ofgetViewId()andgetDomain()combined.protected voidencodePriority(FacesContext context) Renders the<priority>child element with the value ofgetPriority(), if any.Returns the value of the "changefreq" element of the sitemap URL.Returns the domain of the "loc" element of the sitemap URL.Returns the value of the "lastmod" element of the sitemap URL.Returns the value of the "priority" element of the sitemap URL.getValue()Returns the value of the "loc" element of the sitemap URL.Returns the view ID to create the URI part of the "loc" element of the sitemap URL for.voidsetChangeFrequency(SitemapUrl.ChangeFrequency changeFrequency) Sets the value of the "changefreq" element of the sitemap URL.voidSets the domain of the "loc" element of the sitemap URL.voidsetLastModified(Temporal lastModified) Sets the value of the "lastmod" element of the sitemap URL.voidsetPriority(BigDecimal priority) Sets the value of the "priority" element of the sitemap URL.voidSets the value of the "loc" element of the sitemap URL.voidSets the view ID to create the URI part of the "loc" element of the sitemap URL for.Methods inherited from class org.omnifaces.component.output.OutputFamily
getFamily, getRendersChildrenMethods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeAll, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getParent, getPassThroughAttributes, getRenderer, getRendererType, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, visitTreeMethods inherited from class jakarta.faces.component.UIComponent
getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getListenersForEventClass, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, subscribeToEvent, unsubscribeFromEvent
-
Field Details
-
COMPONENT_TYPE
The component type, which is "org.omnifaces.component.output.SitemapUrl".- See Also:
-
-
Constructor Details
-
SitemapUrl
public SitemapUrl()Constructs theSitemapUrlcomponent.- Throws:
IllegalStateException- whenApplication.getProjectStage()isProjectStage.Developmentand the current request is not for theViewResourceHandlerat all.
-
-
Method Details
-
encodeBegin
Renders the start of the<url>parent element.- Overrides:
encodeBeginin classUIComponentBase- Throws:
IOException
-
encodeChildren
Delegates toencodeLocation(FacesContext),encodeLastModified(FacesContext),encodeChangeFrequency(FacesContext)andencodePriority(FacesContext)in this order.- Overrides:
encodeChildrenin classUIComponentBase- Throws:
IOException
-
encodeEnd
Renders the end of the<url>parent element.- Overrides:
encodeEndin classUIComponentBase- Throws:
IOException
-
encodeLocation
Renders the<loc>child element with either the value ofgetValue(), or the value ofgetViewId()andgetDomain()combined.- Parameters:
context- The involved faces context.- Throws:
IOException- When an I/O error occurs.IllegalArgumentException- When thegetDomain()does not represent a valid domain.
-
encodeLastModified
Renders the<lastmod>child element with the value ofgetLastModified(), if any. It may only encode formats specified in https://www.w3.org/TR/NOTE-datetime- Parameters:
context- The involved faces context.- Throws:
IOException- When an I/O error occurs.
-
encodeChangeFrequency
Renders the<changefreq>child element with the value ofgetChangeFrequency(), if any.- Parameters:
context- The involved faces context.- Throws:
IOException- When an I/O error occurs.
-
encodePriority
Renders the<priority>child element with the value ofgetPriority(), if any.- Parameters:
context- The involved faces context.- Throws:
IOException- When an I/O error occurs.IllegalArgumentException- When thegetPriority()is not between 0.0 and 1.0 (inclusive).
-
getValue
Returns the value of the "loc" element of the sitemap URL. Note: when specified, thengetViewId()andgetDomain()are ignored.- Returns:
- The value of the "loc" element of the sitemap URL.
-
setValue
Sets the value of the "loc" element of the sitemap URL. Note: when specified, thengetViewId()andgetDomain()are ignored.- Parameters:
value- The value of the "loc" element of the sitemap URL.
-
getViewId
Returns the view ID to create the URI part of the "loc" element of the sitemap URL for. Note: this is ignored whengetValue()is specified.- Returns:
- The view ID to create the URI part of the "loc" element of the sitemap URL for.
-
setViewId
Sets the view ID to create the URI part of the "loc" element of the sitemap URL for. Note: this is ignored whengetValue()is specified.- Parameters:
viewId- The view ID to create the URI part of the "loc" element of the sitemap URL for.
-
getDomain
Returns the domain of the "loc" element of the sitemap URL. Note: this is ignored whengetValue()is specified.- Returns:
- The domain of the "loc" element of the sitemap URL for.
-
setDomain
Sets the domain of the "loc" element of the sitemap URL. Note: this is ignored whengetValue()is specified.- Parameters:
domain- The domain of the "loc" element of the sitemap URL for.
-
getLastModified
Returns the value of the "lastmod" element of the sitemap URL.- Returns:
- The value of the "lastmod" element of the sitemap URL.
-
setLastModified
Sets the value of the "lastmod" element of the sitemap URL.- Parameters:
lastModified- The value of the "lastmod" element of the sitemap URL.
-
getChangeFrequency
Returns the value of the "changefreq" element of the sitemap URL.- Returns:
- The value of the "changefreq" element of the sitemap URL.
-
setChangeFrequency
Sets the value of the "changefreq" element of the sitemap URL.- Parameters:
changeFrequency- The value of the "changefreq" element of the sitemap URL.
-
getPriority
Returns the value of the "priority" element of the sitemap URL.- Returns:
- The value of the "priority" element of the sitemap URL.
-
setPriority
Sets the value of the "priority" element of the sitemap URL.- Parameters:
priority- The value of the "priority" element of the sitemap URL.
-