我正在尝试创建一个表单,其中FirstName是一个必填字段,以便提交表单(一旦我弄清楚这个错误有什么问题,我会添加其他验证):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Register as a Voter</title>
</h:head>
<h:body>
Please fill out all information below to register as a voter.
<br/>
<h:form id = "form" >
<h:outputLabel value = "First Name:"/>
<h:inputText value = "#{voterBean.firstName}">
<h:validateRequired/>
</h:inputText>
<br/>
<h:outputLabel value = "Last Name:"/>
<h:inputText value = "#{voterBean.lastName}"/>
<br/>
<h:outputLabel value = "Address:"/>
<h:inputText value = "#{voterBean.address}"/>
<br/>
<h:outputLabel value = "City:"/>
<h:inputText value = "#{voterBean.city}"/>
<br/>
<h:outputLabel value = "State"/>
<h:inputText value = "#{voterBean.state}"/>
<br/>
<h:outputLabel value = "Zip:"/>
<h:inputText value = "#{voterBean.zip}"/>
<br/>
<h:outputLabel value = "Phone:"/>
<h:inputText value = "#{voterBean.phone}"/>
<br/>
<h:outputLabel value = "Affiliation:"/> <br/>
<h:selectOneRadio value="#{voterBean.affil}"><br/>
<f:selectItem itemValue="Democrat" itemLabel="Democrat" />
<f:selectItem itemValue="Green Party" itemLabel="Green Party" />
<f:selectItem itemValue="Liberterian" itemLabel="Liberterian" />
<f:selectItem itemValue="Republican" itemLabel="Republican" />
<f:selectItem itemValue="Unafilliated" itemLabel="Unafilliated" />
</h:selectOneRadio>
<br/>
<h:commandButton id = "Submit" value = "Submit" action = "Results"/>
</h:form>
</h:body>
</html>
但是,当我部署此代码并转到此xhtml文件时,我收到一条错误消息
“/ Register.xhtml @ 24,23 Tag Library支持命名空间:http://java.sun.com/jsf/html,但没有为name定义标记:validateRequired”
我已经尝试在stackoverflow上读取此错误的解决方案,但我无法弄清楚问题是什么。
我相信我正确地做到了这一点......
答案 0 :(得分:1)
&#34; validateRequired&#34;标记与核心命名空间而不是html标记相关。将此前缀更改为此<f:validateRequired />
可以解决问题
或者,您可以在输入组件标记内使用required="true"
。他们两人都做同样的事。