Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8409193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:50:16+00:00 2026-06-09T23:50:16+00:00

I got some uncaught exception basically from an SQL operation via Primefaces AJAX call.

  • 0

I got some uncaught exception basically from an SQL operation via Primefaces AJAX call. Interestingly this uncaught exception APPEAR on FireBug’s JavaScript secion as error:

<?xml version='1.0' encoding='UTF-8'?>
<partial-response><error><error-name>class javax.faces.el.EvaluationException</error-name><error-message><![CDATA[Transaction rolled back]]></error-message></error></partial-response>

and on the server.log with all stacktrace and everything.

But I am unable to to bring it to the user attention without redirecting them to a separate error page (and lost all input data).

The proper way to handle this to create validator, which I will do, but there are always possibility of unaware database problem which will only appear doing the SQL operation. So I am only talk about no validator situation.

Let say I have this JSF snippet.

    <h:form>
        <p:messages />
        <..... primefaces (AJX) some button .... action="bean.save()" />
    </h:form>

and the bean.save();

  public void save()
  {
    try
    {
       em.merge(this.data);
    }
    catch(Exception e)
    {
       // never been in here EVEN if the data can't be merge for some constraint breaking reason.
    }
  }

If there is an database error, we will not see it until the transaction ends (AFTER save()) so I can’t catch it. (This is confirmed with debug walk through and the fact that adding “em.flush()” here make the whole things works).

After looked left and right, I created a PhaseListener and I am able to get the exception. However, I am unable to show that exception on <p:messages />

    public void afterPhase(final PhaseEvent event)
    {
        final Iterable exceptionEvents = event.getFacesContext().getExceptionHandler().getUnhandledExceptionQueuedEvents();
        for (final ExceptionQueuedEvent exceptionEvent : exceptionEvents)
        {
            // This print out goes (found in server.log).
            System.out.println("Problem: " + exceptionEvent.getContext().getException());
            // But this message does not.
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,"Problem", "Problem: " + exceptionEvent.getContext().getException()));
        }
    }

Any advice is very appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:50:18+00:00Added an answer on June 9, 2026 at 11:50 pm

    A PhaseListener is not the right place to handle exceptions. You should be using an ExceptionHandler. The only other change you need to make in the code is that you should use Iterator to iterate over the exceptions and use Iterator#remove() to remove the handled exception from the queue. Otherwise it will still be handled by the default exception handler in flavor of that ajax response which you’re seeing.

    See also:

    • What is the correct way to deal with JSF 2.0 exceptions for AJAXified components?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got some code here that isn't working: $(#sidebar ul li:last).each(function(){ $(this).addClass(last); }); Basically I
Got some error in codeigniter when trying to call parent class. This is what
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
I got some pretty messy urls that i got via scraping here, problem is
i've got some problems using jQTouch. I have this Link <a href=#site_map class=swap>Map</a> and
i've got a simple ajax call: function message(){ $.ajax({ type: GET, url: /file/timestamp=+ timestamp,
During compilation of a GWT class I got some compiler exception. I filed a
I got this weird crash in my app, when i try to call this
I got the below error while fetching some data from sever. While fetching data,
i've got some form input elements in an html table like this: <table> <thead>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.