- Type Parameters:
T- The type of the value.
- All Implemented Interfaces:
PartialStateHolder,StateHolder,TransientStateHolder,ValueHolder,ComponentSystemEventListener,FacesListener,SystemEventListenerHolder,EventListener,ParamHolder<T>
<o:pathParam> is a component that extends the OmniFaces Param to support the MultiViews and dynamic route segment
features of FacesViews. It is done by rendering the supplied parameters of such components as <h:link> and
<h:button> among others as path parameters and not as query parameters as otherwise will be produced by <o:param> and
<f:param> tags.
The component has built-in support for a Converter to convert the supplied value to string by usual means via the converter attribute of
the tag, or the nested <f:converter> tag, or just automatically if a converter is already registered for the target class via
@FacesConverter(forClass).
This component doesn't support returning encoded output of its children as parameter value in case no value is present. This feature is provided by
Param component instead.
The name attribute is optional and selects between the two features. Without one the value is appended as the next positional path parameter of a
MultiViews view, which requires MultiViews to be enabled. With one the value instead interpolates into the dynamic route segment of that name,
which requires no MultiViews at all, only a view in a directory whose name is wrapped in square brackets. Both are described below and can be combined on one
view.
MultiViews path parameters
This component is used to create bookmarkable URLs via standard outcome target components that take into account <o:pathParam> tags nested
in the components. The unnamed path parameters will be rendered in the order they were declared for a view id that is defined as a multi view and if the view
was not defined as a multi view then they won't be rendered at all. Additionally, declaring unnamed path parameters for a non-multi view will be logged as a
warning and a faces warning message will be added for any stage different from Production.
In the following example the link to the multi view page will be rendered with two path parameters:
<h:link value="Link" outcome="multiview-supported-path">
<o:pathParam value="first" />
<o:pathParam value="second" />
</h:link>
The code above will be rendered as: <a id="..." name="..." href="/context-path/multiview-supported-path/first/second">Link</a>. The
path parameters will be available via @Inject @Param(pathIndex=0) private String first; and
@Inject @Param(pathIndex=1) private String second; the usual way.
Dynamic route segments
When the name attribute is specified, the value interpolates into the dynamic route segment of that name of the target view, as declared by a directory whose
name is wrapped in square brackets. In the following example the link to /organizations/[id]/members.xhtml is rendered with the segment
id substituted:
<h:link value="Link" outcome="/organizations/[id]/members">
<o:pathParam name="id" value="123" />
</h:link>
The code above will be rendered as: <a id="..." name="..." href="/context-path/organizations/123/members">Link</a>. The segment
value will be available via @Inject @Param(pathName="id") private String id; the usual way.
Every dynamic route segment of the target view must be supplied, as a rendered URL may never contain the square brackets themselves. An unsupplied segment
throws an IllegalArgumentException. The values of the current request are deliberately not inherited, so that a link means the same thing regardless
of the page it is rendered on.
- Since:
- 3.6
- Author:
- Sergey Kuntsel
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe component type, which is "org.omnifaces.component.output.PathParam".static final StringThe prefix of thenameattribute of this component when a name is specified, in which case the value interpolates into the dynamic route segment of that name rather than being appended positionally.static final StringThe predefined value of thenameattribute of this component.Fields inherited from class jakarta.faces.component.UIParameter
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
Methods inherited from class org.omnifaces.component.output.Param
encodeChildren, getConverter, getLocalValue, getRendersChildren, setConverterMethods inherited from class jakarta.faces.component.UIParameter
getFacesContext, getFamily, isDisable, setDisable, setName, setRendered, setValueMethods inherited from class jakarta.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeAll, encodeBegin, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, 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, 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, unsubscribeFromEventMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.faces.component.ValueHolder
setValue
-
Field Details
-
COMPONENT_TYPE
The component type, which is "org.omnifaces.component.output.PathParam".- See Also:
-
PATH_PARAM_NAME_ATTRIBUTE_VALUE
The predefined value of thenameattribute of this component.- See Also:
-
PATH_PARAM_NAME_ATTRIBUTE_PREFIX
The prefix of thenameattribute of this component when a name is specified, in which case the value interpolates into the dynamic route segment of that name rather than being appended positionally.- Since:
- 5.5
- See Also:
-
-
Constructor Details
-
PathParam
public PathParam()
-
-
Method Details
-
getValue
Description copied from interface:ParamHolderReturns the value of the parameter asString. If the converter is set, or if any converter is available byApplication.createConverter(Class), passing the value's class, then return the result ofConverter.getAsString(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent, Object), otherwise return theObject.toString()of the value.- Specified by:
getValuein interfaceParamHolder<T>- Specified by:
getValuein interfaceValueHolder- Overrides:
getValuein classParam<T>- Returns:
- The value of the parameter as
String. - See Also:
-
getName
Description copied from interface:ParamHolderReturns the name of the parameter.- Specified by:
getNamein interfaceParamHolder<T>- Overrides:
getNamein classUIParameter- Returns:
- The name of the parameter.
-