error with redirect using listener JSF 2.0
- by Ray
I have a index.xhtml page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view>
<ui:insert name="metadata" />
<f:event type="preRenderView" listener="#{item.show}" />
<h:body></h:body>
</f:view>
</html>
And in bean class with scope session this method
public void show() throws IOException, DAOException {
ExternalContext externalContext = FacesContext.getCurrentInstance()
.getExternalContext();
//smth
String rootPath = externalContext.getRealPath("/");
String realPath = rootPath + "pages\\template\\body\\list.xhtml";
externalContext.redirect(realPath);
}
i think that I should redirect to next page but I have "browser can't show page"
and list.xhtml (if I do this page as welcome-page I haven't error, it means that error connected with redirect)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<ui:composition template="/pages/layouts/mainLayout.xhtml">
<ui:define name="content">
<h:form></h:form></ui:define></ui:composition>
</h:body>
</html>
in consol i didn't have any error.
in web.xml
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
What can be the reason this problem?