0
votes

I'm trying to create a form where FirstName is a required field to put in order to submit the form (going to add other validations once I can figure out what's wrong with this error):

<?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>

However, when I deploy this code and get to this xhtml file I get an error that says

"/Register.xhtml @24,23 Tag Library supports namespace: http://java.sun.com/jsf/html, but no tag was defined for name: validateRequired"

I've tried reading for solutions for this error on stackoverflow but I can't figure out what's the problem.

I believe I'm doing this correctly....

1

1 Answers

1
votes

The "validateRequired"'s tag is related the core namespace rather than the html one. Changing this prefix to this <f:validateRequired /> should fix the problem.
Alternativly, you can make use of required="true" inside the input component tag. Both of them do the same task.