1

I have a JSF 2.0 with mojara EL 2.2 on tomcat 6 and had it working for some time now during the development. I recently added a form with a command button for login (basic stuff) which checks the username and password in the managed bean at the action doLogin.

public String doLogin(){
    FacesMessage message = null;
    if((username.equals("user"))&&(password.equals("pass")))
        return "testpage.xhtml";
    else
        message = new FacesMessage("Invalid username or password");

    FacesContext.getCurrentInstance().addMessage(null, message);

    return null;
}

The problem is that after it goes through doLogin and returns "testpage.xhtml" the same page is displayed. Even though I have all xhtml's file in the root of WebContent.

In the console of tomcat I get:

The ELResolvers for JSF were not registered with the JSP container.

Passing parameters using EL 2.2 work fine.

I'm using JSF with Facelets.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ice
  • 193
  • 1
  • 2
  • 13

3 Answers3

0

Implicit navigation is introduced since JSF 2.0. In old JSF 1.x you'd need to define a <navigation-rule> in faces-config.xml or to explicitly call ExternalContext#redirect() on an URL.

This problem suggests that your JSF 2.0 web application is running in JSF 1.x fallback modus. Make sure that your faces-config.xml is declared conform JSF 2.0 specification version.

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    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"
    version="2.0">

    <!-- Config here. -->

</faces-config>

The EL resolver warning is unrelated to this this. It's caused by using Glassfish's EL 2.2 on Tomcat 6 and you would be unable to use EL in .jsp pages (which shouldn't be a problem if you're solely using Facelets). If you want to get rid of this warning, use JBoss EL instead of Glassfish EL. JBoss EL is an enhanced EL 2.1 implementation while Glassfish EL is an EL 2.2 implementation.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

I'm not sure, B'coz I don't see another code.

If you don't set specific navigation-rule in faces-config.xml.

Default of $SUB-DIRECTORY1/testpage.xhtml is $SUB-DIRECTORY1/testpage

Peerapat A
  • 420
  • 4
  • 13
0

In JSF 2.0 testpage view translated into implicit navigation. Please change your code likes here,

    public String doLogin(){
       FacesMessage message = null;
       if((username.equals("user"))&&(password.equals("pass"))) {
            return "testpage";
       } else {
            message = new FacesMessage("Invalid username or password");
            FacesContext.getCurrentInstance().addMessage(null, message);
       }
    return null;
}
Sai Ye Yan Naing Aye
  • 6,622
  • 12
  • 47
  • 65