JSF2。无法使用commandButtom重定向

时间:2013-05-18 02:33:38

标签: jsf-2 primefaces

我有commandButtom将我从“login.xhtml”重定向到“home.xhtm”。登录成功但重定向不起作用;没有任何错误。 面-config.xhtml

<navigation-rule>
        <from-view-id>/public/login.xhtml</from-view-id>
        <navigation-case>
        <from-action>#{userLoginBean.login}</from-action>
            <from-outcome>login</from-outcome>
            <to-view-id>/public/home.xhtml</to-view-id>
        </navigation-case>
    </navigation-rule>

托管bean:

@RequestScoped
public class UserLoginBean{
..
...
..

public String login() throws ServletException, IOException{
    try
    {
      ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); 
      HttpServletRequest request = ((HttpServletRequest)context.getRequest());

      ServletResponse resposnse = ((ServletResponse)context.getResponse());
      RequestDispatcher dispatcher = request.getRequestDispatcher("/j_spring_security_check");
      dispatcher.forward(request, resposnse);
      FacesContext.getCurrentInstance().responseComplete();

      System.out.println("logiiiin");
      return "login";
    }
    catch (Exception ex) {
        ex.printStackTrace();
        System.out.println(ex.getMessage());
        System.out.println("Login Failed");
        FacesContext.getCurrentInstance()
                .addMessage(
                        "formLogin",
                        new FacesMessage(FacesMessage.SEVERITY_WARN,
                                "Login or Password Failed",
                                "User Name and Password Not Match!"));
         return"null";
    }

和.xhtml:

<f:facet name="footer">
                <center>
                    <p:commandButton  value="Se connecter" action="#{userLoginBean.login}" />
                </center>
            </f:facet>

1 个答案:

答案 0 :(得分:0)

尝试重定向到没有任何业务逻辑的页面,即返回“登录”;并验证下一页位置