JsDoc Reference - jsf.ajax (original) (raw)

Namespace jsf.ajax

The namespace for Ajax functionality.
Defined in: jsf.js.

Namespace Summary

Constructor Attributes Constructor Name and Description
jsf.ajax The namespace for Ajax functionality.

Method Summary

Method Attributes Method Name and Description
jsf.ajax.addOnError(callback) Register a callback for error handling.
jsf.ajax.addOnEvent(callback) Register a callback for event handling.
jsf.ajax.request(source, event, options) Send an asynchronous Ajax req uest to the server.
jsf.ajax.response(request, context) Receive an Ajax response from the server.

Namespace Detail

jsf.ajax

The namespace for Ajax functionality.

Method Detail

jsf.ajax.addOnError(callback)

Register a callback for error handling.

Usage:


jsf.ajax.addOnError(handleError);
...
var handleError = function handleError(data) {
...
}

Implementation Requirements:

This function must accept a reference to an existing JavaScript function. The JavaScript function reference must be added to a list of callbacks, making it possible to register more than one callback by invoking jsf.ajax.addOnErrormore than once. This function must throw an error if the callbackargument is not a function.

Parameters:

callback

a reference to a function to call on an error


jsf.ajax.addOnEvent(callback)

Register a callback for event handling.

Usage:


jsf.ajax.addOnEvent(statusUpdate);
...
var statusUpdate = function statusUpdate(data) {
...
}

Implementation Requirements:

This function must accept a reference to an existing JavaScript function. The JavaScript function reference must be added to a list of callbacks, making it possible to register more than one callback by invoking jsf.ajax.addOnEventmore than once. This function must throw an error if the callbackargument is not a function.

Parameters:

callback

a reference to a function to call on an event


jsf.ajax.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:

Form serialization should occur just before the request is sent to minimize the amount of time between the creation of the serialized form data and the sending of the serialized form data (in the case of long requests in the queue). Before the request is sent it must be put into a queue to ensure requests are sent in the same order as when they were initiated. The request callback function must examine the queue and determine the next request to be sent. The behavior of the request callback function must be as follows:

Parameters:

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. Theevent 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:

name value
execute space seperated list of client identifiers
render space seperated list of client identifiers
onevent function to callback for event
onerror function to callback for error
params object containing parameters to include in the request
delay If less than delay milliseconds elapses between calls to request() only the most recent one is sent and all other requests are discarded. If the value of delay is the literal string'none' without the quotes, or no delay is specified, no delay is used.
resetValues If true, ensure a post data argument with the name javax.faces.partial.resetValues and the value true is sent in addition to the other post data arguments. This will cause UIViewRoot.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 because UIViewRoot.resetValues() does not descend into the children of the listed components.

The options argument is optional.

Throws:

Error if first required argumentelement is not specified, or if one or more of the components in the options.executelist is a file upload component, but the form's enctype is not set to multipart/form-data


jsf.ajax.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 there is no XML response returned, signal an emptyResponseerror. 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 successevent as outlined in Chapter 13 "Sending Events" section of the spec prose document linked in the overview summary.

Update Element Processing

The update 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.

<update id="javax.faces.ViewRoot">  
   <![CDATA[...]]>  
</update>  

Update the entire DOM replacing the appropriate head and/orbody sections with the content from the response.

<update id="<VIEW_ROOT_CONTAINER_CLIENT_ID><SEP>javax.faces.ViewState<SEP><UNIQUE_PER_VIEW_NUMBER>">  
   <![CDATA[...]]>  
</update>  

locate and update the submitting form'sjavax.faces.ViewState value with theCDATA contents from the response. 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 JSF view. Locate and update the javax.faces.ViewState value for all JSF forms covered in the render target list whose ID starts with the same <VIEW_ROOT_CONTAINER_CLIENT_ID> value.

<update id="<VIEW_ROOT_CONTAINER_CLIENT_ID><SEP>javax.faces.ClientWindow<SEP><UNIQUE_PER_VIEW_NUMBER>">  
   <![CDATA[...]]>  
</update>  

locate and update the submitting form'sjavax.faces.ClientWindow value with theCDATA contents from the response. 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 JSF view. Locate and update the javax.faces.ClientWindow value for all JSF forms covered in the render target list whose ID starts with the same <VIEW_ROOT_CONTAINER_CLIENT_ID> value.

<update id="javax.faces.Resource">  
   <![CDATA[...]]>  
</update>  

append any element found in the CDATA contents which is absent in the document to the document's head section.

<update id="javax.faces.ViewHead">  
   <![CDATA[...]]>  
</update>  

update the document's head section with the CDATAcontents from the response.

<update id="javax.faces.ViewBody">  
   <![CDATA[...]]>  
</update>  

update the document's body section with the CDATAcontents from the response.

<update id="update id">  
   <![CDATA[...]]>  
</update>  

Find the DOM element with the identifier that matches the<update> element identifier, and replace its contents with the <update> element's CDATA contents.

Insert Element Processing

<insert>  
    <before id="before id">  
       <![CDATA[...]]>  
    </before>  
</insert>  
<insert>  
    <after id="after id">  
       <![CDATA[...]]>  
    </after>  
</insert>  

Delete Element Processing

<delete id="delete id"/>  

Find the DOM element whose identifier matches delete id and remove it from the DOM.

Element Attribute Update Processing

<attributes id="id of element with attribute">  
   <attribute name="attribute name" value="attribute value">  
   ...  
</attributes>  

JavaScript Processing

<eval>  
   <![CDATA[...JavaScript...]]>  
</eval>  

Redirect Processing

<redirect url="redirect url"/>  

Cause a redirect to the url redirect url.

Error Processing

<error>  
   <error-name>..fully qualified class name string...<error-name>  
   <error-message><![CDATA[...]]><error-message>  
</error>  

Extract this <error> element's error-name contents and the error-message contents. Signal a serverError passing the errorName and errorMessage. Refer to section "Signaling Errors" in Chapter 13 of the spec prose document linked in the overview summary.

Extensions