• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF, how to throw ajax error in ajax handler  RSS feed

 
daniele licitra
Ranch Hand
Posts: 81
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all.
I have a p:ajax component


The bean method is:

The method search in database all records that match an expression.
if 1 record match, then set selected record with this record;
if #records > 1, then show a dialog for selection (dv11 is the dialog)
if #records == 0, then validation error.

Case #records == 1 is ok;
Case #records == 0 is ok, I see the validation error and the field became red;
case #records >=2 will launch an exception () but the dialog is not shown because (throw bssexception is not the correct way).

How must i set the method for terminate ajax request in a wrong way?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Throwing an error in an AJAX method is not something that the framework was intended to do. Nor is there any benefit in throwing a ValidatorException there. ValidatorExceptions are handled in an earlier phase of the JSF lifecycle, before the AJAX method would be called (validation failures short-circuit the action).

It is sufficient merely to add error messages to you JSF messages collection and/or any private error/status indicators you might have created.

The "onerror" attribute is for handling problems with the AJAX transport mechanism, not for application errors. You will have better luck using the onevent attribute, which can process JS function like this:


Your best bet would be to have the AJAX listener action method set a (possibly invisible) backing bean property that is re-rendered as part of the AJAX action and use this value in the "success" handler to display the dialog.
 
daniele licitra
Ranch Hand
Posts: 81
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:
Your best bet would be to have the AJAX listener action method set a (possibly invisible) backing bean property that is re-rendered as part of the AJAX action and use this value in the "success" handler to display the dialog.


Thanks Tim, i will follow this way.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!