Create new RichFaces Documentation Jira issue

This will launch the RichFaces Jira page - to complete your feedback please login if needed, and submit the Jira.

JBoss.orgCommunity Documentation

6.1.8.  < a4j:jsFunction > available since 3.0.0

expand all Description Details of Usage Reference Data Relevant Resources Links

The <a4j:jsFunction> component allows to perform Ajax requests directly from JavaScript code, invoke server-side data and return it in a JSON format to use in a client JavaScript calls.

As the component uses Ajax request to get data from server it has all common Ajax Action attributes. Hence, "action" and "actionListener" can be invoked, and reRendering some parts of the page fired after calling function.

When using the <a4j:jsFunction> it's possible to initiate the Ajax request from the JavaScript and perform partial update of a page and/or invoke the JavaScript function with data returned by Ajax response.

<body onload="callScript()">
            <a4j:jsFunction name="callScript" data="#{bean.someProperty1}" reRender="someComponent" oncomplete="myScript(data.subProperty1, data.subProperty2)">
                  <a4j:actionparam name="param_name" assignTo="#{bean.someProperty2}"/>

The <a4j:jsFunction> allows to use <a4j:actionparam> or pure <f:param> for passing any number of parameters of the JavaScript function into Ajax request. <a4j:jsFunction> is similar to <a4j:commandButton> , but it could be activated from the JavaScript code. It allows to invoke some server-side functionality and use the returned data in the JavaScript function invoked from "oncomplete" attribute. Hence it's possible to use <a4j:jsFunction> instead of <a4j:commandButton> . You can put it anywhere, just don't forget to use <h:form> and </h:form> around it.

Information about the "process" attribute usage you can find "Decide what to process" guide section.

Table of <a4j:jsFunction> attributes.

Visit the jsFunction page at RichFaces LiveDemo for component usage and sources for the given examples.

Useful articles:

  • "JsFunctionJson" article in the RichFaces Cookbook describes how to use "a4j:jsFunction" to call the jsonTest backing bean that generates some random data in a JSON String;