type=page
status=published
title=Handling Errors
next=jsf-ajax007.html
prev=jsf-ajax005.html
~~~~~~
= Handling Errors


[[GKDCB]]

[[handling-errors]]
Handling Errors
---------------

JavaServer Faces handles Ajax errors through use of the `onerror`
attribute of the `f:ajax` tag. The value of this attribute is the name
of a JavaScript function.

When there is an error in processing a Ajax request, JavaServer Faces
calls the defined `onerror` JavaScript function and passes a data object
to it. The data object contains all the properties available for the
`onevent` attribute and, in addition, the following properties:

* `description`
* `errorName`
* `errorMessage`

The `type` is `error`. The `status` property of the data object contains
one of the valid error values listed in link:#GKGOU[Table 13-4].

[[sthref72]][[GKGOU]]

*Table 13-4 Valid Error Values for the Data Object status Property*

[width="60%",cols="15%,45%"]
|=======================================================================
|*Values* |*Description*
|`emptyResponse` |No Ajax response from server.

|`httpError` |One of the valid HTTP errors: `request.status==null` or
`request.status==undefined` or `request.status<200` or
`request.status>=300`.

|`malformedXML` |The Ajax response is not well formed.

|`serverError` |The Ajax response contains an `error` element.
|=======================================================================


In the following example, any errors that occurred in processing the
Ajax request are handled by the `handlemyajaxerror` JavaScript function:

[source,oac_no_warn]
----
<f:ajax event="click" render="errormessage" onerror="handlemyajaxerror"/>
----
