Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Keep p:dialog open and update error it if validation fail  RSS feed

 
Robert Roberto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I have a page which has 2 parts: a table display all records and a dialog to add a new record. I added some validation features but I can't get them to work properly.
I need it to:
1) Validation error not appear the first time dialog shows up
2) If any validation error happens, keep it open and show error messages.
3) If no validation error and back-end executed succesfully, update the table.

Here's what I have:



Backing bean:



I've tried setting Submit button oncomplete="if (args & amp; & amp; !args.validationFailed) teamDialog_w.hide()" but it doesn't work.
I got it to run properly in one of my previous project without using !args.validationFailed but now I'm unable to replicate the code.

Please help.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The important thing to remember is that the dialog is not a separate window nor does it operate in a separate context. As far as JSF is concerned, it's just another h:form on the current page.

That means that it follows the lifecycle rules for a form. If you submit it, the control values on that form (dialog) will go through the validation, update and action processes (or at least validate) and if validation fails, it will construct JSF messages in the usual way which can be posted back to the form. To avoid refreshing the entire page, this should be running under AJAX (which I believe is the default).

For me, the tricky part was making the dialog go away when valid data was submitted but keeping it displayed (with the validation errors) when one or more fields was invalid. That basically required ensuring that the response to the submit set a property that the post-submit AJAX code could use to hide the dialog. I won't go into details, since I was using RichFaces, but RichFaces has a JSON return feature that not only allowed me to return status, but also non-JSF managed messages.
 
Robert Roberto
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:The important thing to remember is that the dialog is not a separate window nor does it operate in a separate context. As far as JSF is concerned, it's just another h:form on the current page.

That means that it follows the lifecycle rules for a form. If you submit it, the control values on that form (dialog) will go through the validation, update and action processes (or at least validate) and if validation fails, it will construct JSF messages in the usual way which can be posted back to the form. To avoid refreshing the entire page, this should be running under AJAX (which I believe is the default).

For me, the tricky part was making the dialog go away when valid data was submitted but keeping it displayed (with the validation errors) when one or more fields was invalid. That basically required ensuring that the response to the submit set a property that the post-submit AJAX code could use to hide the dialog. I won't go into details, since I was using RichFaces, but RichFaces has a JSON return feature that not only allowed me to return status, but also non-JSF managed messages.


Do you have any suggestion on how to fix this?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My most recent talks with a potential employer here in town that used PrimeFaces fell through. I don't care to work for anyone who's more arrogant than myself. Which, considering, ought to leave a lot of viable candidates, but no...

So most of what I know of Primefaces is either ancient or superficial.

As I said, in RichFaces, my "save" button in the dialog invoked a corresponding "save" method which not only saved the dialog form data, but also set up a return status and message text as backing bean properties. The RichFaces framework allows me to retrieve them as a JSON string which can then be used in a post-commit (oncomplete) javascript to update message text on the client and, in the case of "success" status, to close (hide) the dialog.

Presumably, Primefaces has something equivalent, but I'd have to read the manual and since I don't get paid for this stuff, I'm not in any big hurry.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!