2

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 ?

MattOnyx
  • 172
  • 12
  • 1
    No namespace like `xmlns:jsf="http://xmlns.jcp.org/jsf/passthrough"` is seen. Are you trying to use HTML5 or design a page using plain HTML elements? Use proper JSF tags/attributes along with `passthrough`, if you intend to use it. (and optionally, you should not explicitly restrict yourself to use `ISO-8859-1` whether it is specified with ``). – Tiny Feb 12 '15 at 19:54
  • Thank you for replying @Tiny . Yes I'm trying to use HTML5 support of JSF-2.2 but maybe I'm getting it wrong, since I learned to use an older version. I used `xmlns:jsf="http://xmlns.jcp.org/jsf"`, isn't it ok ? Changing it to `xmlns:jsf="http://xmlns.jcp.org/jsf/passthrough"` had no effect. Can you explain what I'm doing wrong ? – MattOnyx Feb 12 '15 at 20:17
  • I was just suggesting. Once upon a time, this same thing entirely failed to work in my application and I did not try afterwords. Therefore, I am not sure about it. (In my case, there might be some (NetBeans)IDE related quirks which I myself was not clear enough with). – Tiny Feb 12 '15 at 20:25
  • I found this question interesting I hope you get an answer without using your workaround, even if I also don't agree with using `.html` files ( you can take a look at @BalusC answer regarding that: http://stackoverflow.com/a/9829006/4170582) But, I don't understand why this html page don't even call the action method! it's not an navigation issue but the action method is never called! NB: i added ` javax.faces.DEFAULT_SUFFIX .html ` to the `web.xml` file – Tarik Feb 13 '15 at 02:29

1 Answers1

0

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 ?

MattOnyx
  • 172
  • 12
  • You can't post other questions within an answer, so either edit your original question and add this solution as an edit (as personally i prefer to have an answer regarding the first issue than making a workarround). Or you can consider this as an answer and post another different question – Tarik Feb 13 '15 at 02:17