Skip to main content

JSF2: Detecting conversion errors in Ajax requests

2 replies [Last post]
vesuvius
Offline
Joined: 2007-06-02

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:

ajax1.xhtml:

</p>
<p>

Ajax1.java:

<br />
@RequestScoped<br />
@Named<br />
public class Ajax1 {<br />
    private Integer age;</p>
<p>    public Integer getAge() {<br />
        return age;<br />
    }</p>
<p>    public void setAge(Integer age) {<br />
        this.age = age;<br />
    }<br />
}<br />

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"), no error is reported. The response is sent back as if everything is okay. Just that it's NOT okay and the field is cleared.

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

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

inAge: 'aaa' must be a number consisting of one or more digits.

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?

P.S. The response has code 200 (OK). Here's the response contents:

<br />
<?xml version="1.0" encoding="utf-8"?></p>
<p>Age: ]]><br />

No error! Nothing!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ed.Burns@Sun.COM

Do you have an explicit
in your page?

It could be that you need to make sure the clientId for the messages
tag is included in your Ajax request.

Please excuse the terseness of this response. It was sent from a
mobile device.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: webtier-help@glassfish.dev.java.net

vesuvius
Offline
Joined: 2007-06-02

You're right. Thank you!!! Now, the messages are shown.

Indeed, I had [i]both[/i] a global [b][/b] tag, and also a specific [b][/b] tag on the page. I just didn't think of including them in the [b]render[/b] clause of the [b][/b] tag

I suppose the reason is that I'm used to working with ADF Faces and there the messages are re-rendered automatically, I don't have to re-render them [i]explicitly[/i].

I suppose it would be a nice feature of Mojarra itself to re-render the messages automatically -- the global ones as well as the ones attached to components that were executed (or re-rendered?). For example, If I specify:

[code]

[/code]

then Mojarra could automatically re-render the following elements:

1. [b][/b], if there are messages for the component.
2. [b][/b], if available on the page and if there are messages

That's just a convenience, of course. It's not absolute necessity. Probably I like it this way because I'm used to it being this way in ADF Faces.

Again, thank you for your help!