JSF - XHTML 表单上的"no tag was defined for name: validateRequired"错误



我试图创建一个表单,其中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标签库支持命名空间:http://java.sun.com/jsf/html,但没有为name: validaterrequired定义标签"

我试着在stackoverflow上阅读这个错误的解决方案,但我不知道是什么问题。

我相信我这样做是正确的....

" validaterrequired "的标签与核心命名空间相关,而不是与html命名空间相关。将这个前缀更改为这个<f:validateRequired />应该可以解决这个问题。
或者,您可以在输入组件标记中使用required="true"

相关内容

  • 没有找到相关文章

最新更新