The <o:scriptParam>
is a component that extends the standard <f:viewParam>
with support for setting results of client-side evaluated JavaScript code in bean.
It's similar to the <f:viewParam>
.
<f:metadata> <o:scriptParam script="new Date().getTimezoneOffset()" value="#{bean.clientTimeZoneOffset}" /> <o:scriptParam script="window.screen.width" value="#{bean.clientScreenWidth}" /> <o:scriptParam script="someFunctionName()" value="#{bean.resultOfSomeFunctionName}" /> </f:metadata>
You can use the render
attribute to declare which components should be updated when a script parameter
has been set.
<f:metadata> <o:scriptParam script="foo()" value="#{bean.resultOfFoo}" render="fooResult" /> </f:metadata> ... <h:body> ... <h:panelGroup id="fooResult"> <ui:fragment rendered="#{not empty bean.resultOfFoo}"> The result of foo() script is: #{bean.resultOfFoo} </ui:fragment> </h:panelGroup> ... </h:body>
Note that as it extends from the standard <f:viewParam>
, its built-in conversion and validation
functionality is also supported on this component. So, the following is also possible:
<f:metadata> <o:scriptParam script="window.navigator" value="#{bean.clientNavigator}" /> </f:metadata>With a
clientNavigator
being an instance of jakarta.json.JsonObject
:
private JsonObject clientNavigator;And this converter:
package com.example; import java.io.StringReader; import jakarta.faces.component.UIComponent; import jakarta.faces.context.FacesContext; import jakarta.faces.convert.Converter; import jakarta.faces.convert.ConverterException; import jakarta.faces.convert.FacesConverter; import jakarta.json.Json; import jakarta.json.JsonObject; @FacesConverter(forClass = JsonObject.class) public class JsobObjectConverter implements Converter<JsonObject> { @Override public String getAsString(FacesContext context, UIComponent component, JsonObject modelValue) { if (modelValue == null) { return ""; } return modelValue.toString(); } @Override public JsonObject getAsObject(FacesContext context, UIComponent component, String submittedValue) { if (submittedValue == null || submittedValue.isEmpty()) { return null; } try { return Json.createReader(new StringReader(submittedValue)).readObject(); } catch (Exception e) { throw new ConverterException("Not a valid JSON object", e); } } }
Info | Value |
---|---|
Component Type | org.omnifaces.component.input.ScriptParam |
Handler Class | None |
Renderer Type | None |
Description | None |
Name | Required | Type | Description |
---|---|---|---|
script | true | jakarta.el.ValueExpression
(must evaluate to java.lang.String )
| The script to be evaluated. |
converter | false | jakarta.el.ValueExpression
(must evaluate to jakarta.faces.convert.Converter )
| Converter instance registered with this component. |
converterMessage | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String )
| A ValueExpression enabled attribute that, if present, will be used as the text of the converter message, replacing any message that comes from the converter. |
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. |
required | false | jakarta.el.ValueExpression
(must evaluate to boolean )
| Flag indicating that the user is required to provide a submitted value for this input component. This component extends the behavior of this by only making this required for a non-faces request. |
requiredMessage | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String )
| A ValueExpression enabled attribute that, if present, will be used as the text of the validation message for the "required" facility, if the "required" facility is used. |
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 )
| A ValueExpression enabled attribute that, if present, will be used as the text of the validator message, replacing any message that comes from the validator. |
value | false | jakarta.el.ValueExpression
(must evaluate to java.lang.Object )
| A ValueExpression to which the value representing the evaluated result of the script, as determined by the script attribute, is bound. |
render | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String )
| A space separated string of client IDs to update after the script param has been set in bean on page load. |
binding | false | jakarta.el.ValueExpression
(must evaluate to jakarta.faces.component.UIComponent )
| The ValueExpression linking this component to a property in a backing bean |
Output generated by Vdldoc View Declaration Language Documentation Generator.