You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Clint Checketts <ch...@gmail.com> on 2011/03/26 23:28:31 UTC

Wicket Cookbook Questions - ConversionExceptions (pg 30)

I'm really enjoying Igor's Wicket
Cookbook<https://www.packtpub.com/apache-wicket-cookbook/book>(hooray
for ebooks and instant delivery!)

Instead of asking Igor directly, I figure this mailing list is a better
forum.

There is an example (page 30) like the following:

        ConversionException e = new ConversionException(
                "Error converting value: " + value + " to an instance of: "
                        + Time.class.getName());
        *e.setSourceValue(value);*
        e.setVariable("inputPiece", value);
        e.setResourceKey(getClass().getSimpleName() + "." + errorKey);

My question is the purpose of 'setSourceValue()' call. I suspected it was to
leverage the converted value in validation messages, but ${input} already
has that value. Next I figured it could be used for the sub piece of a
conversion, like in parsing a time of day (11:15am) then is the minute
section was wrong (11:99am) the it would expose that specific value, but
setVariable() meets that need:

e.setVariable("inputPiece", value);

The previous line makes ${inputPiece} available in Validation messages.

So what does setSourceValue() do?

-Clint

Re: Wicket Cookbook Questions - ConversionExceptions (pg 30)

Posted by Igor Vaynberg <ig...@gmail.com>.
Hi Clint,
That is there to make the exception more informative in case someone
catches it and interrogates it for the value that caused it.

-Igor


On Sat, Mar 26, 2011 at 3:28 PM, Clint Checketts <ch...@gmail.com> wrote:
> I'm really enjoying Igor's Wicket
> Cookbook<https://www.packtpub.com/apache-wicket-cookbook/book>(hooray
> for ebooks and instant delivery!)
>
> Instead of asking Igor directly, I figure this mailing list is a better
> forum.
>
> There is an example (page 30) like the following:
>
>        ConversionException e = new ConversionException(
>                "Error converting value: " + value + " to an instance of: "
>                        + Time.class.getName());
>        *e.setSourceValue(value);*
>        e.setVariable("inputPiece", value);
>        e.setResourceKey(getClass().getSimpleName() + "." + errorKey);
>
> My question is the purpose of 'setSourceValue()' call. I suspected it was to
> leverage the converted value in validation messages, but ${input} already
> has that value. Next I figured it could be used for the sub piece of a
> conversion, like in parsing a time of day (11:15am) then is the minute
> section was wrong (11:99am) the it would expose that specific value, but
> setVariable() meets that need:
>
> e.setVariable("inputPiece", value);
>
> The previous line makes ${inputPiece} available in Validation messages.
>
> So what does setSourceValue() do?
>
> -Clint
>

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