You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris Lintz <ch...@gmail.com> on 2007/10/17 10:28:38 UTC

StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Hi all,
I swapped beta3 for beta4 and to my surprise all of my StringResourceModels
that have worked (even back to 1.2) suddenly dont work.  The toString() call
no longer returns the resource String. I dont see this in the release notes
so to say the least, this was a very frustrating find.

For example, this use to work:

public String getPageTitle()
{
   return new StringResourceModel("page.title", this, new
Model(this)).toString();
}

Now I have to say:

public String getPageTitle()
{
    StringResourceModel("page.title", this, new Model(this)).getString();
}

A subtle change that that took some time to finally track down... Why did
this change?  I believe the toString() is referenced in many docs.


chris

-- 
View this message in context: http://www.nabble.com/StringResourceModel-toString%28%29-changed-in-Beta4---why-----Must-use-getString%28%29-now.-tf4638851.html#a13249098
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Igor Vaynberg <ig...@gmail.com>.
actually the check you should be doing is:

if (obj instanceof imodel) { return ((imodel)obj.getobject()).tostring(); }

that is the model contract and that is how it is used properly.

-igor


On 10/17/07, Jan Kriesten <ja...@renitence.de> wrote:
>
> Hi Thomas,
>
> > The javadoc pretty clearly says that this is "useful for debugging and
> > so on...". What lead you to believe this would always return a
> > user-readable string?
>
> actually, I stumbled over this, too. I used StringResourceModel for
> IChoiceRenderer- and IOptionRenderer-Lists (where one assumes String within
> getDisplayValue/getIdValue). Now I have to do an
>
> if( obj instanceof StringResourceModel )
>   return( ((StringResourceModel) obj).getString() );
>
> whereas for all other cases I just return 'toString()'.
>
> This wasn't a nice surprise actually.
>
> Regards, --- Jan.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Chris Lintz <ch...@gmail.com>.
I also read documentation - it may have been on the Pro Wicket book.. I dont
recall.  Nonetheless I thought it was strange to also reley on toString()..
but seeing documentation and examples of toString() pushed me into using it
without much thought.  And like I said this worked all the way back to
Wicket 1.2 .  I dont care what it is.. I'll refactor to getString().  It
would just be nice to know ahead of time whats coming.  


Jan Kriesten wrote:
> 
> 
> Hi Thomas,
> 
>> Fair enough, was I reading more importance into the second sentence
>> (useful for debugging...). I still would not rely on toString() for
>> anything but debugging purposes unless someone passes me an object of a
>> well known, final class
> 
> right - but there are exceptions to rules. :-)
> 
> In my case, the documentation for IChoiceRenderer.getIdValue() explicitely
> suggest using toString().
> 
> Anyway, clearifcation of the API or a return to the old behavior is
> needed:
> 
> https://issues.apache.org/jira/browse/WICKET-1080
> 
> Regards, --- Jan.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/StringResourceModel-toString%28%29-changed-in-Beta4---why-----Must-use-getString%28%29-now.-tf4638851.html#a13255680
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Jan Kriesten <ja...@renitence.de>.
Hi Thomas,

> Fair enough, was I reading more importance into the second sentence
> (useful for debugging...). I still would not rely on toString() for
> anything but debugging purposes unless someone passes me an object of a
> well known, final class

right - but there are exceptions to rules. :-)

In my case, the documentation for IChoiceRenderer.getIdValue() explicitely
suggest using toString().

Anyway, clearifcation of the API or a return to the old behavior is needed:

https://issues.apache.org/jira/browse/WICKET-1080

Regards, --- Jan.


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


RE: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Maeder Thomas <th...@ecofin.ch>.
Fair enough, was I reading more importance into the second sentence
(useful for debugging...). I still would not rely on toString() for
anything but debugging purposes unless someone passes me an object of a
well known, final class

cheers

Thomas

> -----Original Message-----
> From: Jan Kriesten [mailto:jan.kriesten@renitence.de] 
> Sent: Mittwoch, 17. Oktober 2007 12:40
> To: users@wicket.apache.org
> Subject: Re: StringResourceModel toString() changed in Beta4 
> - why??? Must use getString() now.
> 
> 
> Hi Thomas,
> 
> > Yes, but you were relying on an implementation detail which 
> was in no 
> > way promised to remain stable. You should not have done 
> that and you 
> > got properly burned.
> 
> not really. The API of StringResourceModel.toString() says:
> 
> "Override of the default method to return the resource string 
> represented by this string resource model."
> 
> So, I would say it's an unforeseeable API change!
> 
> Regards, --- Jan.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 

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


Re: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Jan Kriesten <ja...@renitence.de>.
Hi Thomas,

> Yes, but you were relying on an implementation detail which was in no
> way promised to remain stable. You should not have done that and you got
> properly burned.

not really. The API of StringResourceModel.toString() says:

"Override of the default method to return the resource string represented by
this string resource model."

So, I would say it's an unforeseeable API change!

Regards, --- Jan.


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


Re: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Gwyn Evans <gw...@gmail.com>.
Beta3 said this for toString()

        /**
         * Override of the default method to return the resource string represented
         * by this string resource model. Useful in debugging and so on, to avoid
         * the explicit need to call the getString() method.
         * 
         * @return The string for this model object
         */

and this for getString()

        /**
         * Gets the string currently represented by this string resource model. The
         * string that is returned may vary for each call to this method depending
         * on the values contained in the model and an the parameters that were
         * passed when this string resource model was created.
         * 
         * @return The string
         */


It's arguable that it is/was saying that it could be used to avoid
the explicit getString() call but as it no longer can (as it's being
used to expose internal details for logging/debugging), then it should
really be mentioned in a change note somewhere.

/Gwyn
         
On Wednesday, October 17, 2007, 11:21:56 AM, Maeder <th...@ecofin.ch> wrote:

> Yes, but you were relying on an implementation detail which was in no
> way promised to remain stable. You should not have done that and you got
> properly burned. It's like when you call one of these public methods
> which are marked as "not part of the Wicket API, don't call this". What
> my question was aimed at was more finding out whether the doc specifies
> anything about the return value of StringResourceModel.toString().

> Thomas

>> -----Original Message-----
>> From: Jan Kriesten [mailto:jan.kriesten@renitence.de] 
>> Sent: Mittwoch, 17. Oktober 2007 12:07
>> To: users@wicket.apache.org
>> Subject: Re: StringResourceModel toString() changed in Beta4 
>> - why??? Must use getString() now.
>> 
>> 
>> Hi Thomas,
>> 
>> > The javadoc pretty clearly says that this is "useful for 
>> debugging and 
>> > so on...". What lead you to believe this would always return a 
>> > user-readable string?
>> 
>> actually, I stumbled over this, too. I used StringResourceModel for
>> IChoiceRenderer- and IOptionRenderer-Lists (where one assumes 
>> String within getDisplayValue/getIdValue). Now I have to do an
>> 
>> if( obj instanceof StringResourceModel )
>>   return( ((StringResourceModel) obj).getString() );
>> 
>> whereas for all other cases I just return 'toString()'.
>> 
>> This wasn't a nice surprise actually.
>> 
>> Regards, --- Jan.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>> 
>> 

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



/Gwyn


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


RE: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Maeder Thomas <th...@ecofin.ch>.
Yes, but you were relying on an implementation detail which was in no
way promised to remain stable. You should not have done that and you got
properly burned. It's like when you call one of these public methods
which are marked as "not part of the Wicket API, don't call this". What
my question was aimed at was more finding out whether the doc specifies
anything about the return value of StringResourceModel.toString().

Thomas

> -----Original Message-----
> From: Jan Kriesten [mailto:jan.kriesten@renitence.de] 
> Sent: Mittwoch, 17. Oktober 2007 12:07
> To: users@wicket.apache.org
> Subject: Re: StringResourceModel toString() changed in Beta4 
> - why??? Must use getString() now.
> 
> 
> Hi Thomas,
> 
> > The javadoc pretty clearly says that this is "useful for 
> debugging and 
> > so on...". What lead you to believe this would always return a 
> > user-readable string?
> 
> actually, I stumbled over this, too. I used StringResourceModel for
> IChoiceRenderer- and IOptionRenderer-Lists (where one assumes 
> String within getDisplayValue/getIdValue). Now I have to do an
> 
> if( obj instanceof StringResourceModel )
>   return( ((StringResourceModel) obj).getString() );
> 
> whereas for all other cases I just return 'toString()'.
> 
> This wasn't a nice surprise actually.
> 
> Regards, --- Jan.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 

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


Re: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Jan Kriesten <ja...@renitence.de>.
Hi Thomas,

> The javadoc pretty clearly says that this is "useful for debugging and
> so on...". What lead you to believe this would always return a
> user-readable string?

actually, I stumbled over this, too. I used StringResourceModel for
IChoiceRenderer- and IOptionRenderer-Lists (where one assumes String within
getDisplayValue/getIdValue). Now I have to do an

if( obj instanceof StringResourceModel )
  return( ((StringResourceModel) obj).getString() );

whereas for all other cases I just return 'toString()'.

This wasn't a nice surprise actually.

Regards, --- Jan.


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


RE: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Maeder Thomas <th...@ecofin.ch>.
The javadoc pretty clearly says that this is "useful for debugging and
so on...". What lead you to believe this would always return a
user-readable string?

Thomas


> -----Original Message-----
> From: Chris Lintz [mailto:christopher.justin@gmail.com] 
> Sent: Mittwoch, 17. Oktober 2007 10:29
> To: users@wicket.apache.org
> Subject: StringResourceModel toString() changed in Beta4 - 
> why??? Must use getString() now.
> 
> 
> Hi all,
> I swapped beta3 for beta4 and to my surprise all of my 
> StringResourceModels that have worked (even back to 1.2) 
> suddenly dont work.  The toString() call no longer returns 
> the resource String. I dont see this in the release notes so 
> to say the least, this was a very frustrating find.
> 
> For example, this use to work:
> 
> public String getPageTitle()
> {
>    return new StringResourceModel("page.title", this, new 
> Model(this)).toString(); }
> 
> Now I have to say:
> 
> public String getPageTitle()
> {
>     StringResourceModel("page.title", this, new 
> Model(this)).getString(); }
> 
> A subtle change that that took some time to finally track 
> down... Why did this change?  I believe the toString() is 
> referenced in many docs.
> 
> 
> chris
> 
> --
> View this message in context: 
> http://www.nabble.com/StringResourceModel-toString%28%29-chang
> ed-in-Beta4---why-----Must-use-getString%28%29-now.-tf4638851.
> html#a13249098
> Sent from the Wicket - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 

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


Re: StringResourceModel toString() changed in Beta4 - why??? Must use getString() now.

Posted by Johan Compagner <jc...@gmail.com>.
I will change the javadoc.
The toString() method can't return the string, because for that we need a
lot of state internally and that
state isn't there always when toString() is called (especially in debugging)
So we did get exceptions that things wheren't set and so on.

Also toString is just for debugging except in java for a few String and
primitive Object cases.

johan


On 10/17/07, Chris Lintz <ch...@gmail.com> wrote:
>
>
> Hi all,
> I swapped beta3 for beta4 and to my surprise all of my
> StringResourceModels
> that have worked (even back to 1.2) suddenly dont work.  The toString()
> call
> no longer returns the resource String. I dont see this in the release
> notes
> so to say the least, this was a very frustrating find.
>
> For example, this use to work:
>
> public String getPageTitle()
> {
>   return new StringResourceModel("page.title", this, new
> Model(this)).toString();
> }
>
> Now I have to say:
>
> public String getPageTitle()
> {
>    StringResourceModel("page.title", this, new Model(this)).getString();
> }
>
> A subtle change that that took some time to finally track down... Why did
> this change?  I believe the toString() is referenced in many docs.
>
>
> chris
>
> --
> View this message in context:
> http://www.nabble.com/StringResourceModel-toString%28%29-changed-in-Beta4---why-----Must-use-getString%28%29-now.-tf4638851.html#a13249098
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>