Hello,
This is my jsf code :-
<h:commandButton id="cmdLogin" value="Login" actionListener="#{indexBean.login}">
<f:ajax execute="@form" render="@all" />
</h:commandButton>
This is my login method of indexBean :-
public void login(){
HttpServletResponse objHttpServletResponse = (HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse();
objHttpServletResponse.sendRedirect("Restricted/Home.jsf");
}
I get one alert in javascript emptyResponse: An empty response was received from the server. Check server error logs.
. Why does this type of redirect not work?
EDIT :- Interestingly, when i redirect from faces-config.xml, it works!
<faces-config version="2.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>Home</from-outcome>
<to-view-id>/Restricted/Home.jsf</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
</faces-config>
And obviously, i changed actionListener
of commandbutton to action
and changed return type of login
to String
and returned home
from login method. Can anybody tell now, if this is the desired behaviour in JSF ? How come redirect from faces-config.xml
works and simple redirect in managedbean doesn't?