我在我的操作 ExpenseManagerAction.java 中的重载方法中添加验证逻辑,如下所示:
public void validate(){
if (!StringUtil.matchDateString(expense.getTempDate())) {
addFieldError("expense.tempDate","Date format is invalid");
}
}
我的jsp内容如下:
<s:form action="expenseManagerAction" method="post" theme="simple">
<table width="80%" align="center" border="1" >
<tr>
<td width="50%">Expense ID</td>
<td align="left">
<s:textfield name="expense.expenseId" />
</td>
</tr>
<tr>
<td>PaymentItem</td>
<td align="left">
<s:textfield name="expense.paymentItem" />
</td>
</tr>
<tr>
<td>Comments</td>
<td align="left">
<s:textarea name="expense.comments" rows="10" cols="30" />
</td>
</tr>
<tr>
<td>PaymentDate</td>
<td align="left">
<s:textfield name="expense.tempDate" cssClass="Wdate" /><!-- onClick="WdatePicker()" -->
</td>
</tr>
<tr>
<td>Price</td>
<td align="left">
<s:textfield name="expense.price" />
</td>
</tr>
<tr>
<td>Quantity</td>
<td align="left">
<s:textfield name="expense.quantity" />
</td>
</tr>
<tr>
<td colspan="2" width="100%">
<p>Expert Search(Double click to magnify it)</p>
<s:textarea onmouseover="showTooltip();" tooltip="Double click to magnify it" rows="1" cols="100" id="advanced" name="expertCondition" ondblclick="openExpertSearchWindow();"></s:textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<s:submit type="button" action="expenseManagerAction_smartSearch" value="smartSearch" />
<s:submit type="button" action="expenseManagerAction_reset" value = "Reset" />
<s:submit type="button" id="btnExpSearch" action="expenseManagerAction_search" value = "Expert Search" />
</td>
</tr>
</table>
</s:form>
当我在付款日期文本框中输入无效字符“a”并单击智能搜索按钮时,我可以看到语句 addFieldError("expense.tempDate", "Date format is invalid"); 调试的时候执行了,但是表单上不能显示错误信息,不知道怎么解决。