- Source:
Methods
(static) request(source, event, options)
Send an asynchronous Ajax req uest to the server.
Usage:
Example showing all optional arguments:
<commandButton id="button1" value="submit"
onclick="jsf.ajax.request(this,event,
{execute:'button1',render:'status',onevent: handleEvent,onerror: handleError});return false;"/>
</commandButton/>
Implementation Requirements:
This function must:- Be used within the context of a
form
, else throw an error. - Capture the element that triggered this Ajax request
(from the
source
argument, also known as thesource
element. - If the
source
element isnull
orundefined
throw an error. - If the
source
argument is not astring
or DOM element object, throw an error. - If the
source
argument is astring
, find the DOM element for thatstring
identifier. - If the DOM element could not be determined, throw an error.
- If the
jakarta.faces.ViewState
element could not be found, throw an error. - If the ID of the
jakarta.faces.ViewState
element has a<VIEW_ROOT_CONTAINER_CLIENT_ID><SEP>
prefix, where <SEP> is the currently configuredUINamingContainer.getSeparatorChar()
and <VIEW_ROOT_CONTAINER_CLIENT_ID> is the return fromUIViewRoot.getContainerClientId()
on the view from whence this state originated, then remember it as namespace prefix. This is needed during encoding of the set of post data arguments. - If the
onerror
andonevent
arguments are set, they must be functions, or throw an error. - Determine the
source
element'sform
element. - Get the
form
view state by calling jsf.getViewState passing theform
element as the argument. - Collect post data arguments for the Ajax request.
- The following name/value pairs are required post data arguments:
name value jakarta.faces.ViewState
Contents of jakarta.faces.ViewState hidden field. This is included when jsf.getViewState is used.
jakarta.faces.partial.ajax
true
jakarta.faces.source
The identifier of the element that triggered this request.
jakarta.faces.ClientWindow
Call jsf.getClientWindow(), passing the current form. If the return is non-null, it must be set as the value of this name/value pair, otherwise, a name/value pair for client window must not be sent.
- The following name/value pairs are required post data arguments:
- Collect optional post data arguments for the Ajax request.
- Determine additional arguments (if any) from the
options
argument. Ifoptions.execute
exists:- If the keyword
@none
is present, do not create and send the post data argumentjakarta.faces.partial.execute
. - If the keyword
@all
is present, create the post data argument with the namejakarta.faces.partial.execute
and the value@all
. - Otherwise, there are specific identifiers that need to be sent. Create the post
data argument with the name
jakarta.faces.partial.execute
and the value as a space delimitedstring
of client identifiers.
- If the keyword
- If
options.execute
does not exist, create the post data argument with the namejakarta.faces.partial.execute
and the value as the identifier of the element that caused this request. - If
options.render
exists:- If the keyword
@none
is present, do not create and send the post data argumentjakarta.faces.partial.render
. - If the keyword
@all
is present, create the post data argument with the namejakarta.faces.partial.render
and the value@all
. - Otherwise, there are specific identifiers that need to be sent. Create the post
data argument with the name
jakarta.faces.partial.render
and the value as a space delimitedstring
of client identifiers.
- If the keyword
- If
options.render
does not exist do not create and send the post data argumentjakarta.faces.partial.render
. - If
options.delay
exists let it be the value delay, for this discussion. Ifoptions.delay
does not exist, or is the literal string'none'
, without the quotes, no delay is used. If less than delay milliseconds elapses between calls to request() only the most recent one is sent and all other requests are discarded. - If
options.resetValues
exists and its value istrue
, ensure a post data argument with the namejakarta.faces.partial.resetValues
and the valuetrue
is sent in addition to the other post data arguments. This will causeUIViewRoot.resetValues()
to be called, passing the value of the "render" attribute. Note: do not use any of the@
keywords such as@form
or@this
with this option becauseUIViewRoot.resetValues()
does not descend into the children of the listed components. - Determine additional arguments (if any) from the
event
argument. The following name/value pairs may be used from theevent
object:target
- the ID of the element that triggered the event.captured
- the ID of the element that captured the event.type
- the type of event (ex: onkeypress)alt
-true
if ALT key was pressed.ctrl
-true
if CTRL key was pressed.shift
-true
if SHIFT key was pressed.meta
-true
if META key was pressed.right
-true
if right mouse button was pressed.left
-true
if left mouse button was pressed.keycode
- the key code.
- Determine additional arguments (if any) from the
- Encode the set of post data arguments.
If the
jakarta.faces.ViewState
element has a namespace prefix, then make sure that all post data arguments are prefixed with this namespace prefix. - Join the encoded view state with the encoded set of post data arguments
to form the
query string
that will be sent to the server. - Create a request
context
object and set the properties:source
(the source DOM element for this request)onerror
(the error handler for this request)onevent
(the event handler for this request)
- Send a
begin
event following the procedure as outlined in the Chapter 13 "Sending Events" section of the spec prose document linked in the overview summary - Set the request header with the name:
Faces-Request
and the value:partial/ajax
. - Determine the
posting URL
as follows: If the hidden fieldjakarta.faces.encodedURL
is present in the submitting form, use its value as theposting URL
. Otherwise, use theaction
property of theform
element as theURL
. -
Determine whether or not the submitting form is using
multipart/form-data
as itsenctype
attribute. If not, send the request as anasynchronous POST
using theposting URL
that was determined in the previous step. Otherwise, send the request using a multi-part capable transport layer, such as a hidden inline frame. Note that using a hidden inline frame does not useXMLHttpRequest
, but the request must be sent with all the parameters that a JSFXMLHttpRequest
would have been sent with. In this way, the server side processing of the request will be identical whether or the request is multipart or not.The
begin
,complete
, andsuccess
events must be emulated when using the multipart transport. This allows any listeners to behave uniformly regardless of the multipart orXMLHttpRequest
nature of the transport.
- If the request completed successfully invoke jsf.ajax.response
passing the
request
object. - If the request did not complete successfully, notify the client.
- Regardless of the outcome of the request (success or error) every request in the
queue must be handled. Examine the status of each request in the queue starting from
the request that has been in the queue the longest. If the status of the request is
complete
(readyState 4), dequeue the request (remove it from the queue). If the request has not been sent (readyState 0), send the request. Requests that are taken off the queue and sent should not be put back on the queue.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
source |
The DOM element that triggered this Ajax request, or an id string of the element to use as the triggering element. | |||||||||||||||||
event |
The DOM event that triggered this Ajax request. The
event argument is optional. |
|||||||||||||||||
options |
The set of available options that can be sent as
request parameters to control client and/or server side
request processing. Acceptable name/value pair options are:
options argument is optional. |
- Source:
Throws:
element
is not specified, or if one or more
of the components in the options.execute
list is a file upload component, but the form's enctype
is not set to multipart/form-data
(static) response(request, context)
Receive an Ajax response from the server.
Usage:
jsf.ajax.response(request, context);
Implementation Requirements:
This function must evaluate the markup returned in therequest.responseXML
object and perform the following action:
- If an
<update>
element is found in the response with the identifierjakarta.faces.ViewRoot
:
Update the entire DOM replacing the appropriate<update id="jakarta.faces.ViewRoot"> <![CDATA[...]]> </update>
head
and/orbody
sections with the content from the response. - If an
<update>
element is found in the response with an identifier containingjakarta.faces.ViewState
:
locate and update the submitting form's<update id="<VIEW_ROOT_CONTAINER_CLIENT_ID><SEP>jakarta.faces.ViewState<SEP><UNIQUE_PER_VIEW_NUMBER>"> <![CDATA[...]]> </update>
jakarta.faces.ViewState
value with theCDATA
contents from the response. <SEP> is the currently configuredUINamingContainer.getSeparatorChar()
. <VIEW_ROOT_CONTAINER_CLIENT_ID> is the return fromUIViewRoot.getContainerClientId()
on the view from whence this state originated. <UNIQUE_PER_VIEW_NUMBER> is a number that must be unique within this view, but must not be included in the view state. This requirement is simply to satisfy XML correctness in parity with what is done in the corresponding non-partial Faces view. Locate and update thejakarta.faces.ViewState
value for all Faces forms covered in therender
target list whose ID starts with the same <VIEW_ROOT_CONTAINER_CLIENT_ID> value. - If an
update
element is found in the response with an identifier containingjakarta.faces.ClientWindow
:
locate and update the submitting form's<update id="<VIEW_ROOT_CONTAINER_CLIENT_ID><SEP>jakarta.faces.ClientWindow<SEP><UNIQUE_PER_VIEW_NUMBER>"> <![CDATA[...]]> </update>
jakarta.faces.ClientWindow
value with theCDATA
contents from the response. <SEP> is the currently configuredUINamingContainer.getSeparatorChar()
. <VIEW_ROOT_CONTAINER_CLIENT_ID> is the return fromUIViewRoot.getContainerClientId()
on the view from whence this state originated. <UNIQUE_PER_VIEW_NUMBER> is a number that must be unique within this view, but must not be included in the view state. This requirement is simply to satisfy XML correctness in parity with what is done in the corresponding non-partial Faces view. Locate and update thejakarta.faces.ClientWindow
value for all Faces forms covered in therender
target list whose ID starts with the same <VIEW_ROOT_CONTAINER_CLIENT_ID> value. - If an
update
element is found in the response with the identifierjakarta.faces.Resource
:
append any element found in the<update id="jakarta.faces.Resource"> <![CDATA[...]]> </update>
CDATA
contents which is absent in the document to the document'shead
section. - If an
update
element is found in the response with the identifierjakarta.faces.ViewHead
:
update the document's<update id="jakarta.faces.ViewHead"> <![CDATA[...]]> </update>
head
section with theCDATA
contents from the response. - If an
update
element is found in the response with the identifierjakarta.faces.ViewBody
:
update the document's<update id="jakarta.faces.ViewBody"> <![CDATA[...]]> </update>
body
section with theCDATA
contents from the response. - For any other
<update>
element:
Find the DOM element with the identifier that matches the<update id="update id"> <![CDATA[...]]> </update>
<update>
element identifier, and replace its contents with the<update>
element'sCDATA
contents. - If an
<insert>
element is found in the response with a nested<before>
element:<insert> <before id="before id"> <![CDATA[...]]> </before> </insert>
- Extract this
<before>
element'sCDATA
contents from the response. - Find the DOM element whose identifier matches
before id
and insert the<before>
element'sCDATA
content before the DOM element in the document.
- Extract this
- If an
<insert>
element is found in the response with a nested<after>
element:<insert> <after id="after id"> <![CDATA[...]]> </after> </insert>
- Extract this
<after>
element'sCDATA
contents from the response. - Find the DOM element whose identifier matches
after id
and insert the<after>
element'sCDATA
content after the DOM element in the document.
- Extract this
- If a
<delete>
element is found in the response:
Find the DOM element whose identifier matches<delete id="delete id"/>
delete id
and remove it from the DOM. - If an
<attributes>
element is found in the response:<attributes id="id of element with attribute"> <attribute name="attribute name" value="attribute value"> ... </attributes>
- Find the DOM element that matches the
<attributes>
identifier. - For each nested
<attribute>
element in<attribute>
, update the DOM element attribute value (whose name matchesattribute name
), withattribute value
.
- Find the DOM element that matches the
- If an
<eval>
element is found in the response:<eval> <![CDATA[...JavaScript...]]> </eval>
- Extract this
<eval>
element'sCDATA
contents from the response and execute it as if it were JavaScript code.
- Extract this
- If a
<redirect>
element is found in the response:
Cause a redirect to the url<redirect url="redirect url"/>
redirect url
. - If an
<error>
element is found in the response:
Extract this<error> <error-name>..fully qualified class name string...<error-name> <error-message><![CDATA[...]]><error-message> </error>
<error>
element'serror-name
contents and theerror-message
contents. Signal aserverError
passing theerrorName
anderrorMessage
. Refer to section "Signaling Errors" in Chapter 13 of the spec prose document linked in the overview summary. - The
<extensions>
element provides a way for framework implementations to provide their own information. - The implementation must check if <script> elements in the response can be automatically run, as some browsers support this feature and some do not. If they can not be run, then scripts should be extracted from the response and run separately.
If there is no XML response returned, signal an emptyResponse
error. If the XML response does not follow the format as outlined
in Appendix A of the spec prose document linked in the
overview summary signal a malformedError
error. Refer to
section "Signaling Errors" in Chapter 13 of the spec prose document linked in the
overview summary.
If the response was successfully processed, send a success
event as outlined in Chapter 13 "Sending Events" section of the spec prose
document linked in the
overview summary.
Update Element Processing
Theupdate
element is used to update a single DOM element. The
"id" attribute of the update
element refers to the DOM element that
will be updated. The contents of the CDATA
section is the data that
will be used when updating the contents of the DOM element as specified by the
<update>
element identifier.
Insert Element Processing
Delete Element Processing
Element Attribute Update Processing
JavaScript Processing
Redirect Processing
Error Processing
Extensions
Parameters:
Name | Type | Description |
---|---|---|
request |
The XMLHttpRequest instance that
contains the status code and response message from the server. |
|
context |
An object containing the request context, including the following properties: the source element, per call onerror callback function, and per call onevent callback function. |
- Source: