JSF导航规则不适用于表单提交 [英] JSF navigation rule doesn't work on form submit
问题描述
我试图用JSF制作几个非常简单的HTML页面,以搜索数据库中的某些内容,但是由于某种原因,当我按下提交"按钮时,什么也没发生.文本输入为空,什么也没有发生.它应该转到显示结果的另一页.
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.
这是我的文件:
index.html
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
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
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 ?
推荐答案
我找到了一种方法.
我似乎将jsf标记为未渲染,因此我将每个html文件都切换为xhtml并在web.xml
中进行了更改
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>
对此
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
它解决了问题,但是当我尝试使用HTML5时,现在我需要尊重xhtml严格语法.有什么建议吗?
It solved the problem, but now I need to respect xhtml strict syntax, while I try to use HTML5. Any suggestion ?
这篇关于JSF导航规则不适用于表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!