The <o:hashParam> is a component that extends the standard <f:viewParam> with support for setting hash query parameter
values in bean and automatically reflecting updated model values in hash query string.
The "hash query string" is the part in URL after the # which could be formatted in the same format as a regular request query string (the part
in URL after the ?). An example:
https://example.com/page.xhtml#foo=baz&bar=kaz
This specific part of the URL (also called hash fragment identifier) is by default not sent to the server. This component will on page load and on every
window.onhashchange event send it anyway so that the Faces model gets updated, and on every Faces ajax request update the hash query string in
client side when the Faces model value has changed.
It's very similar to the <o:viewParam>.
<f:metadata>
<o:hashParam name="foo" value="#{bean.foo}" />
<o:hashParam name="bar" value="#{bean.bar}" />
</f:metadata>
You can use the render attribute to declare which components should be updated when a hash parameter value is present.
<f:metadata>
<o:hashParam name="foo" value="#{bean.foo}" render="fooResult" />
<o:hashParam name="bar" value="#{bean.bar}" />
</f:metadata>
...
<h:body>
...
<h:panelGroup id="fooResult">
...
</h:panelGroup>
...
</h:body>
In case you need to invoke a bean method before rendering, e.g. to preload the rendered contents based on new hash param values, then you can observe the
HashChangeEvent. See the "Events" section for an usage example.
You can use the default attribute to declare a non-null value which should be interpreted as the default value. In other words, when the current
model value matches the default value, then the hash parameter will be removed.
<f:metadata>
<o:hashParam name="foo" value="#{bean.foo}" />
<o:hashParam name="bar" value="#{bean.bar}" default="kaz" />
</f:metadata>
When #{bean.foo} is "baz" and #{bean.bar} is "kaz" or empty, then the reflected hash query string will
become https://example.com/page.xhtml#foo=baz. If #{bean.bar} is any other value, then it will appear in the hash query string.
Note that as it extends from the standard <f:viewParam>, its built-in conversion and validation functionality is also supported on this
component.
When the hash query string is changed by the client side, e.g. by following a #foo=baz&bar=kaz link, or by manually manipulating the URL,
then a CDI HashChangeEvent will be fired which can be observed in any CDI managed bean as below:
public void onHashChange(@Observes HashChangeEvent event) {
String oldHashString = event.getOldValue();
String newHashString = event.getNewValue();
// ...
}
This is useful in case you want to preload the model for whatever is rendered by <o:hashParam render>.
| Info | Value |
|---|---|
| Component Type | org.omnifaces.component.input.HashParam |
| 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. |
converter | false | jakarta.el.ValueExpression
(must evaluate to jakarta.faces.convert.Converter)
| No Description |
converterMessage | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| No Description |
default | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| The default value in case the actual hash parameter is null or empty. |
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. |
immediate | false | jakarta.el.ValueExpression
(must evaluate to boolean)
| No Description |
name | true | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| The name of the request parameter from which the value for this component is retrieved on an initial request or to override the stored value on a postback. |
render | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| A space separated string of client IDs to update on ajax response. |
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. |
required | false | jakarta.el.ValueExpression
(must evaluate to boolean)
| No Description |
requiredMessage | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| No Description |
validator | false | jakarta.el.MethodExpression
(signature must match void validate(jakarta.faces.context.FacesContext, jakarta.faces.component.UIComponent, java.lang.Object))
| MethodExpression representing a validator method that will be called during Process Validations to perform correctness checks on the value of this component. The expression must evaluate to a public method that takes FacesContext, UIComponent, and Object parameters, with a return type of void. |
validatorMessage | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String)
| No Description |
value | false | jakarta.el.ValueExpression
(must evaluate to java.lang.Object)
| No Description |
valueChangeListener | false | jakarta.el.MethodExpression
(signature must match void valueChange(jakarta.faces.event.ValueChangeEvent))
| MethodExpression representing a value change listener method that will be notified when a new value has been set for this input component. The expression must evaluate to a public method that takes a ValueChangeEvent parameter, with a return type of void, or to a public method that takes no arguments with a return type of void. |
Output generated by Vdldoc View Declaration Language Documentation Generator.