my project is on JSF 1.2 and IceFaces. It works perfectly. I thought of adding error pages, to avoid showing that ugly exceptions page.
This is what I did :
web.xml
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.xhtml</location>
</error-page>
error.xhml
<html>
<body>
<center>
<h1> HELLO THIS IS AN ERROR</h1>
</center>
</body>
I made a link in the application that generates the exception. But when I click on it, I just get nothing, neither the Hello message, neither the classic exception stack trace message.
Should I add some code to FacesConfig or something?
Related
I use Web Flow and JSF, so they works well actually. But I am trying to find out alternative way for set default page different from redirecting on index.html.
The main problem is web analytics scripts don't work properly. I can't track user source fore home page.
The application run on Tomcat 8
Web.xml
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
index.html
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=web/home-page">
</head>
</html>
UPDATE :
I replace index.html with index.jsp and I set response status as 301. At least it works for google analytics, so I'll check it out for other analytics tools.
But this solution still did not satisfy me.
Web.xml
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
index.jsp
<%
response.setStatus(301);
String path=(String)request.getAttribute("javax.servlet.forward.request_uri");
if(path==null){
path="web/home-page";
}
response.setHeader( "Location", path);
response.setHeader( "Connection", "close" );
%>
I would use spring security project instead of welcome files because JSF (or any view framework) is not aware how to resolve a view in welcome-file that is why your logic is not executing.
A possible solution is if you are using the spring security project. Add the following to your security config
<security:http auto-config="true" use-expressions="true">
<!--- config omitted for brevity -->
<security:session-management invalid-session-url="/index.jsp"/>
</security:http>
Again this is just a sample. You can also use other means to define rules. It is quite modular
<security:intercept-url pattern="/**" ....
Moreover, you will need to define a classless controller with the following defintion: (assuming you also are using Spring MVC with Webflow)
<mvc:view-controller path="/index.jsp" />
I think it's less cryptic to define intercept,forward,routing, etc... rules all in Spring Security config that way it is clear that any such rules are stored in one place.
Note: you might be able to keep your current setup and use that spring <mvc:view-controller path="/index.jsp" /> definition only to trigger the JSF to execute.
I am working on JSF 2.2 with PrimeFaces 5.1, in my application for exception handling I have configured error code 500 in web.xml like below
<error-page>
<error-code>500</error-code>
<location>/500.xhtml</location>
</error-page>
and in 500.xhtml I am trying to access error code like below
<h:outputText value="#{requestScope['javax.servlet.error.status_code']}"></h:outputText>
at the time of testing I found that, I was redirected to a url like below
https://localhost:8443/appname/500.xhtml
which is wrong it should like https://localhost:8443/appname/configerd_path
and here I found that in requestScope I don't have javax.servlet.error.*
so I cannot display error code, error message and so on ...
I would like to ask here that, what is the best practice to handle this kind of error in JSF 2.2 and how can I access error code and error message ?
As I am using primefaces and it's provides a built-in exception handler to take care of exceptions in ajax and non-ajax request easily.
with the following EL, I am able to catch exception at my 500.xhtml page.
<h:outputText value="#{pfExceptionHandler.exception}" ></h:outputText>
<h:outputText value="#{pfExceptionHandler.type}"></h:outputText>
<h:outputText value="#{pfExceptionHandler.message}" ></h:outputText>
I hope it helps others :-)
I want unhandled exceptions to be printed to console so that I can just click on exception to go to the line causing exception.
But they are printed to the browser and I couldn't find any setting for that.
I am using JSF 2.2 with myfaces implementation and tomcat as container.
You can use a special page for exceptions instead of showing exceptions. The exception trace will still be written into the log but it will not be displayed to users.
web.xml
<error-page>
<error-code>404</error-code>
<location>/errorpages/404.xhtml</location>
</error-page>
<error-page>
<exception-type>javax.ejb.EJBException</exception-type> // Your exception type
<location>/errorpages/404.xhtml</location>
</error-page>
I have created a web application using JSF 2.0. I got feedback from my friend saying I should do "Browser Caching" as I have many images.
However I don't know how to do same in JSF. Any idea/ hint would be appreciated.
Concept on what to be done would also work.
Just use <h:graphicImage name="..."> instead of <img src="...">. This way the default JSF resource handler will instruct the browser to cache them for 1 week by default, which is configureable with an implementation dependent context parameter, which is the following in case of Mojarra:
<context-param>
<param-name>com.sun.faces.defaultResourceMaxAge</param-name>
<param-value>3628800000</param-value> <!-- 6 weeks -->
</context-param>
Note, the same applies when using <h:outputScript> and <h:outputStylesheet> instead of <script> and <link rel="stylesheet">.
My all application is written with jsf 1.2
I want to use from this moment on facelets where xhtml files are .
So I have some main questions:
1.I want to
face one:upgrade to jsf 1.2 with servlets
face two:from there to upgrade to 2.0
would this two changes break my application ?
2.how to do this ? can some one explain to me ? I have been trying all day long to do it i had :
changed a file to xhtml amd changed his taglibs to xmlns such as :
<%# taglib prefix="a4j" uri="http://richfaces.org/a4j" %> will be converted to : xmlns:a4j="http://richfaces.org/a4j"
adding
<view-handler>
com.sun.facelets.FaceletViewHandler
</view-handler>
inside application in the faces config
changing file name from xxx.jsp to xxx.xhtml
adding
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
to web xml
inserting
f:view tag above all
the problem i am facing now
when *.jsf page is called the server says no page like this exists in the system...
when *.xhtml is called the page itself is blank and the server asks me to download it meaning a pop up with open and save options popes.