If my JSF applications, I'll sometimes come across a bug that, for example, corrupts a user session bean somewhere and the user is stuck looking # a bunch of java exception gobbly-gook on their screen. The only way they can fix this is to restart their browser.
Instead, I would like the application to handle something like this gracefully...basically by being able to catch any of these uncaught exceptions and display an error message (and or possibly contain a link to allow the user to logout/login so they don't have to restart their browser).
Is there a way for JSF to do this easily? If not, does anyone have a solution for this?
You can just create a custom error page and define its location in <error-page> in web.xml.
E.g.
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
You've all freedom to make it look like the way you want.
Aim for the solution proposed by BalusC since in the long term is the easier thing to maintain, otherwise you could try something like this (actually I already did something similar by defining my own custom view handler for exception handling): Custom JSF/Facelet Exception Handling
Related
This is in continuation with my previous question. I couldn't find solution for that. Hence I am trying to debug my application view layer jspx.
I realized that jspx is quite different from jsp, like it doesn't allow scriptlets. I know, that usage of this(scriptlets) is not at all recommended.
I have a particular SAP Net weaver server where hot deployment of jspx/jsp/html is not working. I have checked other alternatives like remote debugging, break points in jspx. But, its SAP net weaver, have some configuration issues. I have one option atleast to put sysouts, to trace runtime exceptions. But as its jspx files sysouts in scriptlets are not working. If it was jsp instead of jspx there, I could have traced/debugged the issues quickly using scriptlets temporarily until the issue got resolved atleast by using Sysouts.
Is there any equivalent code to this scriptlet(used in jsp)which we use very rarely.
<% System.out.println("The line above the null pointer exception : "+object.getPropery());%
Any equivalent code in jspx or icefaces components.
How do we debug a jspx page or handle exceptions inside a jspx page and find out errors.
Any eclipse plugins or tools available?
I have the following error-pages in my web.xml file:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/pages/inactivity.jsf</location>
</error-page>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/pages/error.jsp</location>
</error-page>
The problem is the following:
Sometimes, I get the ViewExpiredException, and it goes to the inactivity page, but, seems like some .xhtml file tries to use something that's not in session anymore, then I generally got a NullPointerException. But, the second error is a child of the first one, so, my first error handle should be enought.
I was wondering if is there a way to made error-page for a specific exception-type not be showned in some specific page (in inactivity, in my case).
Is there a way to do this?
BTW: I'm using JSF 1.2.
EDIT
Complete Exception.
Also, I just realized that it dont happens in Firefox, just chrome. Dont test in IE because I dont have it :)
I'm using JSF1.2, Tomcat 6.0, RichFaces 3.3.3, and Java 6u31.
I do an action in the managed bean, and show a message to the user. That's OK.
After that, I do another action in managed, and then the messages doesn't work anymore until I refresh the page.
I can assure you that the problem isn't in the managed bean, because I just removed all the method impl, leaving it empty, and the bug still happens.
So, the problem is something in the xhtml pages. I tried to put an a4j:status, but it doenst show any error.
So, I see myself without hope. I will not post all the code here, because it's too big and complex.
I wonder if one of you ever seen something like this, or if you have one guess of whats happening. I can edit the question adding any info you want.
I solve this problem.
I has a onupload in the rich:fileupload.
I just remove it, and add a a4j:support, like this:
<a4j:support event="onupload" oncomplete="foo()" />
That's it. I just don't understand why it works that way, and doesnt in the old way.
BTW, thanks.
I'm using the inputRichText component for composing HTML-formatted messages in a system I'm working on.
I've encountered a problem, however. It seems the session times out, even when the user is working in the editor.
I tried setting the session timeout parameter in web.xml to 1 minute and started typing in the editor. After 1 minute the "User session expired" dialog box appeared. Is there any way to make the rich text editor component keep the session alive? It's pretty annoying to work on something for a while only to loose it to a session time out, event though you haven't been inactive.
This is the code I use to display the component in the page:
<ice:inputRichText height="250" toolbar="MyToolbar" customConfigPath="/FCKconfig.js" id="messageBody" value="#{bean.messageBody}" language="sv" saveOnSubmit="true" />
Thanks!
Edit:
I solved it using a periodic JavaScript calling into a servlet implementing the stuff outlined in this IceFaces JIRA report
If there's a better way, please let me know :)
I solved it using a periodic JavaScript calling into a servlet implementing the stuff outlined in this IceFaces JIRA report.
It basically allows a servlet to "touch" the session and hence keep it alive.
If there's a better way, please let me know :)
I would like to log the exceptions that are thrown when serving JSF files in the same way other exceptions are logged in our web application.
We annotate classes with logged exceptions with #LoggedExceptions and a MehtodInterceptor is matched against those classes with Guice AOP (This should be very similar for other implementations of aopalliance...)
The main problem is, that the method interceptor does not work. How can i intercept method calls on JSF-backing code?
You must replace the default el-resolver (<el-resolver> in faces-context.xml) with a Guice el-resolver, so that the jsf beans become instantiated by Guide.
Search for "Guice el resolver", or take this one (I can't guarantee it works). Also check this thread.
Also, read the top results of this google search