CommandScript is an extension to <h:commandXxx>
which generates a JavaScript
function in the global JavaScript scope which allows the enduser to execute a JSF ajax request by a just function
call functionName()
in the JavaScript context.
The <o:commandScript>
component is required to be enclosed in an UIForm
component. The
name
attribute is required and it represents the JavaScript function name. The execute
and render
attributes work exactly the same as in <f:ajax>
. The onbegin
and oncomplete
attributes must represent (valid!) JavaScript code which will be executed before sending
the ajax request and after processing the ajax response respectively. The action
,
actionListener
and immediate
attributes work exactly the same as in
<h:commandXxx>
.
Basic usage example of <o:commandScript>
which submits the entire form on click of a plain HTML
button:
<h:form> <h:inputText value="#{bean.input1}" ... /> <h:inputText value="#{bean.input2}" ... /> <h:inputText value="#{bean.input3}" ... /> <o:commandScript name="submitForm" action="#{bean.submit}" render="@form" /> </h:form> <input type="button" value="submit" onclick="submitForm()" />
Usage example which uses the <o:commandScript>
as a poll function which updates every 3 seconds:
<h:form> <h:dataTable id="data" value="#{bean.data}" ...>...</h:dataTable> <o:commandScript name="updateData" action="#{bean.reloadData}" render="data" /> </h:form> <h:outputScript target="body">setInterval(updateData, 3000);</h:outputScript>The component also supports nesting of
<f:param>
, <f:actionListener>
and
<f:setPropertyActionListener>
, exactly like as in <h:commandXxx>
. The function
also supports a JS object as argument which will then end up in the HTTP request parameter map:
functionName({ name1: "value1", name2: "value2" });
With the above example, the parameters are in the action method available as follows:
String name1 = Faces.getRequestParameter("name1"); // value1 String name2 = Faces.getRequestParameter("name2"); // value2
Info | Value |
---|---|
Component Type | org.omnifaces.component.script.CommandScript |
Handler Class | None |
Renderer Type | None |
Description | None |
Name | Required | Type | Description |
---|---|---|---|
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. |
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. |
binding | false | jakarta.el.ValueExpression
(must evaluate to jakarta.faces.component.UIComponent )
|
The ValueExpression linking this component to a property in a backing bean.
|
name | true | jakarta.el.ValueExpression
(must evaluate to java.lang.String )
| The script function name. |
execute | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String )
| A space separated string of client IDs to process on ajax request. |
render | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String )
| A space separated string of client IDs to update on ajax response. |
onbegin | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String )
| A script to execute before ajax request is fired. |
oncomplete | false | jakarta.el.ValueExpression
(must evaluate to java.lang.String )
| A script to execute after ajax response is processed. |
autorun | false | jakarta.el.ValueExpression
(must evaluate to boolean )
| Whether the command script should automatically run inline during page load. Note that this thus runs immediately at the moment the script is been interpreted by the web browser and thus not in end of HTML body or during window load event. So if the script logic depends on the HTML DOM tree composition, then it will depend on location of the command script component itself. |
action | false | jakarta.el.MethodExpression
(signature must match java.lang.Object action() )
|
MethodExpression representing the application action to invoke when this component is
activated by the user. The expression must evaluate to a public method that takes no parameters, and
returns an Object (the toString() of which is called to derive the logical
outcome) which is passed to the NavigationHandler for this application.
|
actionListener | false | jakarta.el.MethodExpression
(signature must match void actionListener(jakarta.faces.event.ActionEvent)
)
|
MethodExpression representing an action listener method that will be notified when this
component is activated by the user. The expression must evaluate to a public method that takes an
ActionEvent parameter, with a return type of void, or to a public method that takes no
arguments with a return type of void. In the latter case, the method has no way of easily knowing
where the event came from, but this can be useful in cases where a notification is needed that
"some action happened".
|
immediate | false | jakarta.el.ValueExpression
(must evaluate to boolean )
| Flag indicating that, if this component is activated by the user, notifications should be delivered to interested listeners and actions immediately (that is, during Apply Request Values phase) rather than waiting until Invoke Application phase. |
Output generated by Vdldoc View Declaration Language Documentation Generator.