1

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.

Santo
  • 27
  • 1
  • 6

2 Answers2

3

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

Oliver
  • 3,815
  • 8
  • 35
  • 63
RJo
  • 15,631
  • 5
  • 32
  • 63
2

Looking at the API Docs for DateValidator i can see that based on the condition that failed wicket used different error keys ..like : DateValidator.range, DateValidator.minimum, DateValidator.maximum. You can use this keys and create your custom error messages for this situations.

mvlupan
  • 3,536
  • 3
  • 22
  • 35