webtier@glassfish.java.net

JSF2: Detecting conversion errors in Ajax requests

From: <webtier_at_javadesktop.org>
Date: Tue, 02 Mar 2010 10:21:41 PST

Hi,

I have a problem with conversions in JSF Ajax requests. More specifically, if I enter a non-number into a field that expect a number, the Ajax request doesn't report any error whatsoever.

For example:

[b]ajax1.xhtml:[/b]

[code]
<h:form prependId="false">
    <h:inputText id="inAge" value="#{ajax1.age}" />

    <h:commandButton id="btnPostback" value="Postback">
        <f:ajax execute="inAge" render="outAge"/>
    </h:commandButton>

    <h:outputLabel id="outAge" value="Age: #{ajax1.age}" />
</h:form>
[/code]

[b]Ajax1.java:[/b]

[code]
@RequestScoped
@Named
public class Ajax1 {
    private Integer age;

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
[/code]

This is the simplest example I could think of. It has an input field, a Ajax-enabled button, and an output field that gets updated with the input field's value when the button is pressed.

Now, when I enter a number into the input field, everything works fine.

However, if I enter a non-number (e.g. "aaa"), [b]no error is reported[/b]. The request is sent back as if everything is okay. Just that it's [b]NOT[/b] okay and the field is cleared.

[b]This looks like a bug.[/b] There's no error/stacktrace in the server's log (GlassFish v3). If I specify an onerror function in the <f:ajax> tag, it's NOT called. Complete silence and serenity. [b]But I need to know of the conversion error, so that I can report it to the user.[/b]

NOTE: If I send a plain non-Ajax request, I get an error:

[code]inAge: 'aaa' must be a number consisting of one or more digits.[/code]

That's exactly what I would expect I would get in the Ajax response too.

Am I doing something wrong or is Mojarra doing something wrong?
[Message sent by forum member 'vesuvius' (vesuvius_prime_at_hotmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=389666