我的addNew.xhtml
页面中有很多字段。我必须对客户端的字段进行验证。其中一个领域是city
.
city
如果我不输入which says ,我想得到一个验证错误city cannot be left blank
。
以前我在研究 grails 框架,自定义验证是一项非常容易的任务。现在我正在研究 jsf,我无法在互联网上找到解决这个问题的好例子。
你能帮我实现这个验证吗
<!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"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="../css/global.css" />
</head>
<body>
<div class="windowContents">
<a4j:form style="width: 700px; height: 500px" ajaxSubmit="true"
id="addNewRecord">
<a4j:repeat value="#{addAction.editedtable}"
var="address">
<br />
<br />
<table border="0" style="font-size: 12px; width: 100%;">
<tr>
<td><h:outputText value="File ID:" /></td>
<td><h:outputText value="#{address.fileId}" /></td>
<td><h:outputText value="Insured Name" />:</td>
<td><h:outputText value="#{dataEntryAction.insuredName}" /></td>
</tr>
<tr>
<td><h:outputText value="House No" /><span class="red">*</span>:</td>
<td><h:inputText value="#{address.houseNumber}" /></td>
<td><h:outputText value="Street" /><span class="red">*</span>:</td>
<td><h:inputText value="#{address.street}" /></td>
</tr>
<tr>
<td><h:outputText value="City" />:</td>
<td><h:inputText id ="city" value="#{address.city}" required="false" requiredMessage="City is required" /></td>
<h:message for="city" />
</tr>
</table>
</a4j:repeat>
<br />
<h:panelGroup rendered="true">
<a4j:commandButton value="save" image="../images/buttons/save.gif"
render="@form"
action="#{addAction.saveEditedAndPrepareHistory(addAction.userComment,user, addAction.editedtable)}"
reRender="dataEnrtyTable,dataEntryDetails"
oncomplete="javascript:Richfaces.hideModalPanel('addNewRecordPanel')"
style="align:center;" />
</h:panelGroup>
</a4j:form>
</div>