You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Anna Simbirtsev <as...@gmail.com> on 2011/06/27 19:48:08 UTC

Distinguish between error messages for date

Hi,

I have a date text field and I want to give 2 different error messages for
different errors:
1) invalid date
2) invalid date format


DateTextField myField = new DateTextField("myField",
                "yyyy-MM-dd") {

            private static final long serialVersionUID = 1L;

            public IConverter getConverter(Class<?> type)
              {
                DateConverter converter = new DateConverter()
                {
                    private static final long serialVersionUID = 1L;

                    /**
                     * @see
org.apache.wicket.util.convert.converters.DateConverter#getDateFormat(java.util.Locale)
                     */
                    @Override
                    public DateFormat getDateFormat(Locale locale)
                    {
                        SimpleDateFormat dateFormat = new
SimpleDateFormat("yyyy-MM-dd");
                        dateFormat.setLenient(false);

                        return dateFormat;
                    }
                };

                return converter;
              }
        };
        add(myField);

I put this into properties file but it gives same message for both cases.
iprRegistered.IConverter.Date=my message

Thanks

Re: Distinguish between error messages for date

Posted by Igor Vaynberg <ig...@gmail.com>.
you can write your own converter that distinguishes the two situations
and throws a ConversionException with an appropriate resource key.

-igor

On Mon, Jun 27, 2011 at 10:48 AM, Anna Simbirtsev <as...@gmail.com> wrote:
> Hi,
>
> I have a date text field and I want to give 2 different error messages for
> different errors:
> 1) invalid date
> 2) invalid date format
>
>
> DateTextField myField = new DateTextField("myField",
>                "yyyy-MM-dd") {
>
>            private static final long serialVersionUID = 1L;
>
>            public IConverter getConverter(Class<?> type)
>              {
>                DateConverter converter = new DateConverter()
>                {
>                    private static final long serialVersionUID = 1L;
>
>                    /**
>                     * @see
> org.apache.wicket.util.convert.converters.DateConverter#getDateFormat(java.util.Locale)
>                     */
>                    @Override
>                    public DateFormat getDateFormat(Locale locale)
>                    {
>                        SimpleDateFormat dateFormat = new
> SimpleDateFormat("yyyy-MM-dd");
>                        dateFormat.setLenient(false);
>
>                        return dateFormat;
>                    }
>                };
>
>                return converter;
>              }
>        };
>        add(myField);
>
> I put this into properties file but it gives same message for both cases.
> iprRegistered.IConverter.Date=my message
>
> Thanks
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org