Search code examples
wicketwicketstuff

Customised Error Message for default DateValidator in Wicket


I'm using DateValidator class to validate the date entered by user. I'm getting generic error message for this. Can I customise the error message without creating a separate Validator class.


Solution

  • Yes, for example if you have the following kind of page.

    MyPage.html

    <wicket:page>
        <form wicket:id="form">
            <input type="text" wicket:id="startDate" />
            <input type="text" wicket:id="endDate" />
        </form>
    </wicket:page>
    

    Then you add next to your java class a properties file named MyPage.properties in which you add the following entries.

    MyPage.properties

    form.startDate.DateValidator.minimum=<message for minimum startDate>
    form.startDate.DateValidator.maximum=<message for maximum startDate>
    form.endDate.DateValidator.minimum=<message for minimum endDate>
    form.endDate.DateValidator.maximum=<message for maximum endDate>
    

    You can use variables like ${input} or ${label} to be substituted in the feedback messages.

    A good place to start is in the Wiki of Apache Wicket at https://cwiki.apache.org/confluence/x/N1IB