Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I clear error messages? Not sure if I'm doing this right.

 
Rob Micah
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a page that displays a form and when it's submitted it displays a PDF report. The user might back up multiple times to re-submit this form to see the report with different parameters. If the user makes a mistake by entering invalid data the page fails validation and displays errors. If the user then corrects those errors and re-submits the form, the report will run. But if they back up after submitting the form those old errors from the previous submission are still displayed. I am looking for a way to clear the errors in the <h:messages> tags from the page when the user backs up. Is there any way to do this?

As an example here's a description of what happens:

  • User visits url for first time
  • User submits form with invalid data
  • Validation fails and re-displays page populating <h:message> tags
  • User corrects form data and submits
  • PDF is output
  • User presses back button and sees old errors

  •  
    Guy deLyonesse
    Ranch Hand
    Posts: 200
    Eclipse IDE Java Ubuntu
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You should discourage the use of the back button and instead allow them to go back using a commandLink or button on the page. That forces the app to cycle through the JSF life cycle and clear the message queue.
     
    Bertjan Underhill
    Greenhorn
    Posts: 12
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi,

    try this, add the next line of code after the user re-submits the form (in the methode of your backingbean):

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic