我在我的动作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”并单击smartSearch按钮时,我可以看到语句addFieldError(“expense.tempDate”,“日期格式无效”);我调试时执行但是错误信息无法在表单上显示,我不知道如何解决。
答案 0 :(得分:0)
<s:form>
代码指定了"simple"
主题。"simple"
theme does not render field errors。选项包括: