0
我添加在重載的方法的驗證邏輯在我的動作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」,「Date format is invalid」);當我調試它時執行,但錯誤信息無法顯示在窗體上,我不知道如何解決它。