JSF navigation rule doesn't work on form submit [duplicate]

橙三吉。 提交于 2020-01-02 21:41:30

问题


I'm trying to make a very simple couple of HTML pages with JSF, to search for something in a database, but for some reason, when I hit the submit button, nothing happens. The text input goes empty and nothing else happen. It should go to another page displaying the results.

Here are my files :

index.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:jsf="http://xmlns.jcp.org/jsf">
<head>
<meta charset="ISO-8859-1">
<title>Accueil</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="card">
        <h1>Cinésthésie</h1>
        <form jsf:id="Form_Recherche">
            <div class="inputWrapper">
                <input type="text" id="recherche" jsf:value="beanFilm.recherche" required><label>Que recherchez-vous ?</label>
            </div>
            <input type="submit" value="" id="searchButton" jsf:action="#{beanFilm.doRecherche}"/>
        </form>
    </div>
</body>
</html>

face-config.xml

<?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">
    <managed-bean>
        <managed-bean-name>beanFilm</managed-bean-name>
        <managed-bean-class>bean.BeanFilm</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
        <display-name>index.html</display-name>
        <from-view-id>/index.html</from-view-id>
        <navigation-case>
            <from-outcome>toResultatsRecherche</from-outcome>
            <to-view-id>/resultatsRecherche.html</to-view-id>
        </navigation-case>
    </navigation-rule>

</faces-config>

BeanFilm.java

public class BeanFilm implements Serializable {

    private static final long serialVersionUID = 1L;

    private String recherche = new String();

    public String getRecherche() {
        return recherche;
    }

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

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

    public List<Film> getResultatsRecherche() {
        return DAOFilmJPA.getInstance().getFilmsByTitle(recherche);
    }

}

I've been trying for hours now, I must have missed an important point I guess. Any idea ?


回答1:


I found a way.

I seemed that jsf tags where not rendering so I switched every html file to xhtml and changed in web.xml this

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

to this

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

It solved the problem, but now I need to respect xhtml strict syntax, while I try to use HTML5. Any suggestion ?



来源:https://stackoverflow.com/questions/28486470/jsf-navigation-rule-doesnt-work-on-form-submit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!