1

I tried to reproduce the same example in this question using JSF 2.2.6 and Tomcat 7.0: JSF navigation rule doesn't work on form submit, I also read the JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output and respected all the recommandations provided by BalusC's answer, then I also consulted this question JSF 2 with HTML pages instead of XHTML because I want to use only .html files (I know i can use .xhtml but i need to understand the reason why this is not working).

I tried to make it simple as much as possible so any one could reproduce that:

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"
   version="2.5">
<servlet>
    <servlet-name>facesServlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
   <welcome-file-list>
      <welcome-file>faces/index.html</welcome-file>
   </welcome-file-list>
   <context-param>
      <param-name>javax.faces.PROJECT_STAGE</param-name>
      <param-value>Development</param-value>
   </context-param>
   <context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.html</param-value>
</context-param>
</web-app>

faces-config.xml (Navigation rules are not needed as it's provided dynamicly):

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
    version="2.2">

    <navigation-rule>
        <display-name>index.html</display-name>
        <from-view-id>/index.html</from-view-id>
        <navigation-case>
            <from-outcome>welcomePage</from-outcome>
            <to-view-id>/welcome.html</to-view-id>
        </navigation-case>
    </navigation-rule>

</faces-config>

BeanFilm.java:

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class BeanFilm implements Serializable {

    private String recherche = new String();

    public String getRecherche() {
        return recherche;
    }

    public void setRecherche(String recherche) {
        this.recherche = recherche;
    }

    public String doRecherche() {
        return "welcomePage";
    }


}

index.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<title>Accueil</title>
</head>
<body jsf:id="body" >
        <h1>Plain HTML5 with JSF</h1>
        <form jsf:id="form">
                <input type="text" jsf:id="recherche" jsf:value="#{beanFilm.recherche}"/>
            <input type="submit" jsf:value="Submit" jsf:id="searchButton" jsf:action="#{beanFilm.doRecherche}"/>
        </form>
    <ui:debug/>
</body>
</html>

welcome.html:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<title>Accueil</title>
</head>
<body>

 <h1>Welcome</h1>        

</body>
</html>

The issue:

The exact problem is that when i click on the submit the method BeanFilm#doRecherch() is never called (using a breakpoint) and i can't really understand why? another information wich may be useful, is that in HTML code source attributes are still like jsf:id="searchButton"does this mean that the HTML wasn't generated?

Community
  • 1
  • 1
Tarik
  • 4,961
  • 3
  • 36
  • 67
  • 2
    Reproduced. Works just fine if you get rid of default suffix and stick to `*.xhtml` mapping. Don't have the time to investigate it this weekend, but I can tell that this all should indeed work, apart from the wrong `web.xml` version declaration. – BalusC Feb 14 '15 at 09:41
  • @BalusC "Works just fine if you get rid of default suffix and stick to `*.xhtml` mapping" is that mean if we only modify ` facesServlet *.xhtml ` and ` javax.faces.DEFAULT_SUFFIX .xhtml ` this will work, without midifying any other thing? even files extensions? because when i did only that my app is still not working – Tarik Feb 14 '15 at 14:41
  • Just everything to default, including file extensions. With only faces servlet mapped on `*.xhtml` and nothing else changed. – BalusC Feb 16 '15 at 07:23
  • @BalusC any news why this is not working with `*.html` (hope I'm not bothering you with that)? – Tarik Mar 07 '15 at 12:52

0 Answers0