【发布时间】:2014-09-23 15:09:57
【问题描述】:
我的问题是,当用户在页面之间导航时,用户输入不会被提交和验证。
当时我正在学习 JSF 并编写应用程序。该应用程序由多个页面组成。我使用默认模板插入导航模板。
这是我的导航模板
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough">
<ui:insert name="navigation">
<nav>
<h:panelGroup>
<h:form>
<h:commandButton value="GO BACK" styleClass="button" action="GOBACK"/>
<h:commandButton value="Reset" pt:type="Reset" styleClass="button" action="RESET"/>
<h:commandButton value="GO FORWARD" action="GOFORWARD" styleClass="button"/>
</h:form>
</h:panelGroup>
</nav>
</ui:insert>
</ui:composition>
这是我的 default.xhtml 模板
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title><ui:insert name="title">Page</ui:insert></title>
<h:outputStylesheet library="css" name="normalize.css"/>
<h:outputStylesheet library="css" name="atmosphere.css"/>
<h:outputStylesheet library="css" name="layout.css"/>
</h:head>
<h:body>
<div id="container">
<div id="header">
<ui:include src="header.xhtml"/>
</div>
<div id="content">
<ui:insert name="content">
Content area. See comments below this line in the source.
</ui:insert>
</div>
<div id="navigation">
<ui:insert name="navigation">
<ui:include src="navigation.xhtml"></ui:include>
</ui:insert>
</div>
</div>
</h:body>
</html>
在 faces-config 我有一些导航规则,例如:
<navigation-rule>
<display-name>firstPage.xhtml</display-name>
<from-view-id>/firstPage.xhtml</from-view-id>
<navigation-case>
<from-outcome>GOFORWARD</from-outcome>
<to-view-id>/secondPage.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
现在我想制作一个内容模板客户端,其中包含<h:form>。但是现在的问题是,当用户按下其中一个导航按钮时,用户输入没有得到验证和提交(因为导航是另一种形式)。你知道解决办法吗? (或者我在额外模板中的导航走错路了?)
我唯一的想法是在 default.xhtml 模板中的内容和导航部分周围写一个<h:form>。
谢谢。
【问题讨论】:
-
这在技术上与您的问题无关,但您真的不应该使用您的
faces-config文件来定义导航案例,这些应该在您的个人文件中甚至在您的支持豆。
标签: forms jsf navigation submit