Java Platform, Enterprise Edition (Java EE) 8
The Java EE Tutorial

Previous Next Contents

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 Table 13-4.

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

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:

<f:ajax event="click" render="errormessage" onerror="handlemyajaxerror"/>

Previous Next Contents
Oracle Logo  Copyright © 2017, Oracle and/or its affiliates. All rights reserved.