- 
- All Implemented Interfaces:
- EditableValueHolder,- PartialStateHolder,- StateHolder,- TransientStateHolder,- ValueHolder,- ComponentSystemEventListener,- FacesListener,- SystemEventListenerHolder,- EventListener
 
 public class ScriptParam extends OnloadParam 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.UsageIt'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 renderattribute 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 aclientNavigatorbeing an instance ofjakarta.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); } } }EventsWhen the script params have been set, then any method with the PostScriptParamannotation will be fired:@PostScriptParam public void initScriptParams() { // ... }This is useful in case you want to preload the model for whatever is rendered by <o:scriptParam render>.- Since:
- 3.6
- Author:
- Bauke Scholtz
- See Also:
- OnloadParam,- PostScriptParam,- Faces.getScriptParameters()
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class jakarta.faces.component.UIViewParameterUIViewParameter.Reference
 
- 
 - 
Field SummaryFields Modifier and Type Field Description static StringCOMPONENT_TYPEThe component type, which is "org.omnifaces.component.input.ScriptParam".static StringEVENT_VALUEThe omnifaces event value, which is "setScriptParamValues".- 
Fields inherited from class org.omnifaces.component.input.OnloadParamstate
 - 
Fields inherited from class jakarta.faces.component.UIViewParameterCOMPONENT_FAMILY
 - 
Fields inherited from class jakarta.faces.component.UIInputALWAYS_PERFORM_VALIDATION_WHEN_REQUIRED_IS_TRUE, CONVERSION_MESSAGE_ID, EMPTY_STRING_AS_NULL_PARAM_NAME, REQUIRED_MESSAGE_ID, UPDATE_MESSAGE_ID, VALIDATE_EMPTY_FIELDS_PARAM_NAME
 - 
Fields inherited from class jakarta.faces.component.UIComponentATTRS_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 SummaryConstructors Constructor Description ScriptParam()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddecodeAll(FacesContext context)Decode all relevantOnloadParamcomponents at once.protected StringgetEventValue(FacesContext context)Returns the value of theOmniFaces.OMNIFACES_EVENT_PARAM_NAMEassociated with the current component.protected StringgetInitScript(FacesContext context)Returns script which should be executed upon initialization of a new view.StringgetScript()Returns the script to be evaluated.static booleanisScriptParamRequest(FacesContext context)Returnstrueif the current request is triggered by a script param request.voidsetScript(String script)Sets the script to be evaluated.- 
Methods inherited from class org.omnifaces.component.input.OnloadParamdecodeImmediately, getRender, getUpdateScript, isOnloadParamRequest, isOnloadParamRequest, processDecodes, processUpdates, processValidators, setRender
 - 
Methods inherited from class jakarta.faces.component.UIViewParameterdecode, encodeAll, getConvertedValue, getFamily, getName, getStringValue, getStringValueFromModel, getSubmittedValue, isImmediate, setName, setSubmittedValue, updateModel
 - 
Methods inherited from class jakarta.faces.component.UIInputaddValidator, addValueChangeListener, clearInitialState, compareValues, getConverterMessage, getRequiredMessage, getValidator, getValidatorMessage, getValidators, getValue, getValueChangeListener, getValueChangeListeners, isEmpty, isLocalValueSet, isRequired, isValid, markInitialState, removeValidator, removeValueChangeListener, resetValue, restoreState, saveState, setConverterMessage, setImmediate, setLocalValueSet, setRequired, setRequiredMessage, setValid, setValidator, setValidatorMessage, setValue, setValueChangeListener, validate, validateValue
 - 
Methods inherited from class jakarta.faces.component.UIOutputgetConverter, getLocalValue, setConverter
 - 
Methods inherited from class jakarta.faces.component.UIComponentBaseaddClientBehavior, addFacesListener, broadcast, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getRendersChildren, getValueBinding, invokeOnComponent, isRendered, isTransient, processRestoreState, processSaveState, queueEvent, removeFacesListener, restoreAttachedState, saveAttachedState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEvent
 - 
Methods inherited from class jakarta.faces.component.UIComponentgetClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression, visitTree
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface jakarta.faces.component.ValueHoldergetConverter, getLocalValue, setConverter
 
- 
 
- 
- 
- 
Field Detail- 
COMPONENT_TYPEpublic static final String COMPONENT_TYPE The component type, which is "org.omnifaces.component.input.ScriptParam".- See Also:
- Constant Field Values
 
 - 
EVENT_VALUEpublic static final String EVENT_VALUE The omnifaces event value, which is "setScriptParamValues".- See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getInitScriptprotected String getInitScript(FacesContext context) Description copied from class:OnloadParamReturns script which should be executed upon initialization of a new view.- Overrides:
- getInitScriptin class- OnloadParam
- Parameters:
- context- The involved faces context.
- Returns:
- Script which should be executed upon initialization of a new view.
 
 - 
getEventValueprotected String getEventValue(FacesContext context) Description copied from class:OnloadParamReturns the value of theOmniFaces.OMNIFACES_EVENT_PARAM_NAMEassociated with the current component.- Specified by:
- getEventValuein class- OnloadParam
- Parameters:
- context- The involved faces context.
- Returns:
- The value of the OmniFaces.OMNIFACES_EVENT_PARAM_NAMEassociated with the current component.
 
 - 
decodeAllprotected void decodeAll(FacesContext context) Description copied from class:OnloadParamDecode all relevantOnloadParamcomponents at once.- Specified by:
- decodeAllin class- OnloadParam
- Parameters:
- context- The involved faces context.
 
 - 
getScriptpublic String getScript() Returns the script to be evaluated.- Returns:
- The script to be evaluated.
 
 - 
setScriptpublic void setScript(String script) Sets the script to be evaluated.- Parameters:
- script- The script to be evaluated.
 
 - 
isScriptParamRequestpublic static boolean isScriptParamRequest(FacesContext context) Returnstrueif the current request is triggered by a script param request. I.e. if it is initiated byOmniFaces.ScriptParam.setScriptParamValues()script which runs on page load.- Parameters:
- context- The involved faces context.
- Returns:
- trueif the current request is triggered by a script param request.
 
 
- 
 
-