2

I'm running out of ideas by now, and don't know what else to try. The point is not even one error-page is working, I just would like to know, what am I doing wrong?, here is the code:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/sessionexpired.xhtml</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/500.xhtml</location>
</error-page>

When having this code in my web.xml I get this message:

XML read error: no element found

What this message means? how can I solve this? Thanks.

BTW, I have also tried to use filters to handle the ViewExpiredException, then it works the first time when I send the POST message and redirects to the sessionexpired.xhtml. But if I click backward and then make the POST call again BAM! I get again the ViewExpiredException.

UPDATE 30-NOV-2011 --[ALTERNATE SOLUTION]-------------------------------------

After a while I found that in order to make it work you have to specify the loation to .html or .jsp files, so it would end up being:

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/sessionexpired.html</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/500.jsp</location>
</error-page>
Joe Almore
  • 4,036
  • 9
  • 52
  • 77
  • Hi Bresh Gurung, yes that's a very detailed answer but didn't work either. The problem is the message it throws "XML read error: no element found - Location http://localhost:8080/XXXXXXX - Line Number 1 Column 1", any idea what could be causing that? – Joe Almore Nov 09 '11 at 04:52
  • Which Glassfish version? How does your `` root declaration look like? Who is giving that error message? Your editor or Glassfish itself? Is there really nothing more in that error? I'd expect to see line and column number as well. – BalusC Nov 09 '11 at 11:34
  • 1
    I am using Glassfish 3.1; the error message is shown by the browser; yes there is a line number 1 column number 1. I finally ended up by creating an ExceptionHandlerFactory, this way I could catch the ViewExpiredException. As I read in a forum, it seems to be a bug in Glassfish 3.1, they said they will fix it for the next version. – Joe Almore Nov 11 '11 at 06:20
  • Where and when exactly are you getting this error? There is after all some ambiguity. Do you get this when saving the web.xml or when the IDE validates the web.xml or when the container want to parse web.xml? Or do you get this error in the error page itself? – BalusC Nov 11 '11 at 11:55
  • I already answered that question, the error is shown in the browser. I set the session timeout to 1, then I test the application and force it to show the sessionexpired.xhtml, and I end up getting that error "in the browser [Firefox and IE]" (XML read error: no element found - Location localhost:8080/XXXXXXX - Line Number 1 Column 1) instead of the sessionexpired.xhtml page. I will publish the solution to this later with the use of ExceptionHandlerFactory. – Joe Almore Nov 11 '11 at 17:39
  • I now finally understand your problem. I posted an answer. There's really no need for an exception handler. – BalusC Nov 11 '11 at 17:54

3 Answers3

1

Well, for those that are strugling with this issue using Glassfish 3.1, you can handle that problem by following this article to the letter, even thought I changed at the end to use sendRedirect() instead of the JSF navigator to render the sessionexpired.xhtml file, but that's your choice, it works fine. Here you go:

http://weblogs.java.net/blog/edburns/archive/2009/09/03/dealing-gracefully-viewexpiredexception-jsf2

Joe Almore
  • 4,036
  • 9
  • 52
  • 77
0

After you change the web.xml, have you do the ear or war redeployment? Some of the application server might cache the old copy of web.xml if you directly go to server to modify the file. Hopefully it can work. :)

hejiaming007
  • 341
  • 3
  • 12
0

When having this code in my web.xml I get this message:

 XML read error: no element found

As per the comments it turns out that you're seeing this in the browser instead of the expected error page. I initially interpreted it being mentiond by your IDE/editor due to a syntax error in web.xml. Your question wasn't entirely clear on that.

Well, the solution to that is easy: make sure that the <location> of the <error-page> matches the URL pattern of the FacesServlet. Easiest would be to just map the FacesServlet on an URL pattern of *.xhtml.


BTW, I have also tried to use filters to handle the ViewExpiredException, then it works the first time when I send the POST message and redirects to the sessionexpired.xhtml. But if I click backward and then make the POST call again BAM! I get again the ViewExpiredException.

This is just caused by the page being requested from the browser cache instead of straight from the server. See also this answer for a concrete solution: browser back + viewscope beans.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi BalusC, thanks for your answer but it's still not working. The URL pattern I have for **FacesServlet** is ***.xhtml** (as usual), the **** of the **** is the same as posted above in my question and it shows the same error in the browser with yellow background BTW. – Joe Almore Nov 11 '11 at 18:17
  • That error is browser specific. You seem to be using FF which indeed presents a XML error like that. Well, rightclick page and view source. What do you see? Is it empty? Or is it unparsed? Use Firebug and check request/response headers. What do they say? Especially the response content type. – BalusC Nov 11 '11 at 18:20
  • It's getting **HTTP/1.1 500 Internal Server Error** as result,and the source code of the result starts with ****. I have also tried to catch the error code 500 from the web.xml, but it's just useless, no error page is working from there. May be I should try using another machine, or something could be wrong with the installation of the Glassfish I use, I really don't know. It tries to catch error using the web.xml, but on its way another error is caused while parsing a XML File, that's all I know. – Joe Almore Nov 11 '11 at 18:44
  • Ah right, the error page template itself seems to contain a XHTML syntax error and Facelets felt over it while parsing it. Does that also happen when you open the error page directly by entering its URL in browser address bar? Can you try to edit your question to include the smallest possible but complete snippet of the error page which still reproduces the problem? – BalusC Nov 11 '11 at 18:46
  • Np, if I access directly from the URL the page (sessionexpire.xhtml) renders fine. As I told you this is solved using ExceptionHandlerFactory by now, until the people from Glassfish decide to release a fix to this version 3.1; I'll post the solution later. Thanks for your effort. – Joe Almore Nov 11 '11 at 19:08
  • Okay. I know how to create an exception handler (factory) though. It's only a bit a clumsy solution for this, but it's after all just a workaround. – BalusC Nov 11 '11 at 19:12
  • Yes, as you say, at least it's a decent workaround and solves the problem; at the end what matter most is to be able to continue working. – Joe Almore Nov 11 '11 at 19:15