I am using the ?faces-redirect=true
in my JSF2, since I would like to redirect the user so the URL will be changed.
In JSF1.2 I added </redirect>
in faces-config.
In JSF2 I have to add to my url return home?faces-redirect=true.
The problem is that I see faces-redirect=2
in the URL, what I haven't seen in JSF1.2 when I used </redirect>
How can I use faces-redirect in actions without displaying it in the browser URL?
My Jar's list:
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>OnBoard</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<description></description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/applicationContext.xml
classpath:/applicationContext-security.xml
</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.forceLoadConfiguration</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.BUILD_BEFORE_RESTORE</param-name>
<param-value>false</param-value>
</context-param>
<filter>
<filter-name>Security Page Filter</filter-name>
<filter-class>com.mycompany.servlet.SecurityFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Security Page Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<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>*.jsf</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
JSF by default performs a server page forward while navigating to another page and the URL of the application does not change. To enable the page redirection, append faces-redirect=true at the end of the view name.
NavigateUrl is the property of Hyperlink where URL is defined and navigates to a given link. Where as response. redirect (pageurl) navigates to defined page url.
Navigation between different pages of a JavaServer Faces application, such as choosing the next page to be displayed after a button or hyperlink component is clicked, is defined by a set of rules. Navigation rules can be implicit, or they can be explicitly defined in the application configuration resource file.
Just return it as action method return value. If you're in turn not doing anything else than navigating, then you could also just put the string outcome directly in action attribute.
This looks all fine. Something else is disturbing it. Maybe Spring? I don't do Spring so I can't tell anything about it. At least, it works fine here with Mojarra 2.0.2 + PrimeFaces 2.1 + Tomcat 6.0.24.
To nail this problem down anyway, consider creating a brand new web project with only jsf-api.jar
and jsf-impl.jar
files in the /WEB-INF/lib
and two simple XHTML files with a <h:commandButton outcome="otherfile?faces-redirect=true" />
. Then add libraries/components/mappings step by step until you get the same setup as the original project. Test the working of faces-redirect
during every step. Keep track of what you've added so that you know what may have caused this problem.
That's not what I'm experiencing with Mojarra (the RI). If I return the following in a managed bean:
return "somepage" + "?faces-redirect=true";
JSF redirects to the target somepage
view and the URL doesn't include the ?faces-redirect=true
.
What implementation are you using?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With