如果用户没有选择 spring web mvc 下拉框的任何值,如何显示验证错误消息。无法使用@Notnull 和@Notempty,因为我正在使用@manytoone 映射另一个bean 值。如何做到这一点?谢谢
@Entity()
@Table(name = "QuestionType")
public class QuestionType {
@Id
@GeneratedValue
@Column(name = "id", nullable = false)
private int id;
@Column(name = "questionTypeName", length = 25, nullable = false)
@Pattern(regexp="[a-z|A-Z|\\s]+$",message = "*invalid")
@Size(max = 25, message = "*invalid")
@NotEmpty(message = "*")
private String questionTypeName;
@ManyToOne
//Here not able to use @Notnull & NotEmpty. I'm getting validator should not be used for primitive type
@JoinColumn(name = "domainid", referencedColumnName = "id", insertable = true, updatable = true)
private Domain domainId;
//getters and setters omited
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="../../tlds/spring-form.tld"%>
<%@ taglib prefix="core" uri="../../tlds/c.tld"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Question Type Page</title>
<link href="../../css/default.css" rel="stylesheet" />
</head>
<body>
<form:form commandName="questionType" action="QuestionTypePage.htm" method="post">
<table style="width: 100%; height: 100%;">
<tr height="20px">
<td><span class="label_Heading">Question Type</span></td>
</tr>
<tr height="30px">
<td><form:hidden path="id" />
<div align="center" style="width: 100%; border: solid 1px;"
class="div_Padding">
<span class="label_Normal">Question type</span> <span><form:input
cssClass="textbox_Normal" path="questionTypeName" maxlength="25"/> <form:errors
cssClass="errorMsg" path="questionTypeName" /> </span>
</div>
<div align="center" style="width: 100%; border: solid 1px;"
class="div_Padding">
<span class="label_Normal">Domain</span>
<span>
<form:select path="domainId.id">
<form:option value="0">Select</form:option>
<core:forEach items="${domainList}" var="domain">
<form:option value="${domain.id}">${domain.domainName}</form:option>
</core:forEach>
</form:select><form:errors path="domainId.id" cssClass="errorMsg"/>
</span>
</div></td>
</tr>
<tr height="20px">
<td class="line_Normal">
<table style="width: 100%;">
<tr>
<td><label class="statusMsg">Status :</label><label
class="statusMsg_Small">${statusMsg}</label></td>
<td align="right"><input type="submit" name="button"
value="${buttonValue}" class="button_Normal" /></td>
</tr>
</table>
</td>
</tr>
</form:form>
</body>
</html>