验证消息无法显示

时间:2012-05-06 06:53:27

标签: java struts2

我在我的动作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”,“日期格式无效”);我调试时执行但是错误信息无法在表单上显示,我不知道如何解决。

1 个答案:

答案 0 :(得分:0)

选项包括:

  • 以每个字段为基础覆盖主题
  • 不使用表格的简单主题
  • 创建自定义主题
  • 手动渲染字段错误