You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Martin Makundi <ma...@koodaripalvelut.com> on 2009/07/25 10:46:58 UTC

Make sure you are not calling Component#getString() inside your Component's constructor.

Hi!

I get this warning: Make sure you are not calling
Component#getString() inside your Component's constructor.

Because normally I implement wicket code like this:

XYZComponent extends xxx  {

    public XYZComponent(String id) {
        add(new Label("idxyz", getString("localized_label")); //
Sometimes like this, sometimes just using <wicket:message key="xyz"/>
    }
}

Is there some other phase to have the Component code, other than
constructor such that it is always called ONCE per object
instantiation and preferably in the some specific order if there are
child components?

Or what is the best-practice to avoid these warnings: "Make sure you
are not calling Component#getString() inside your Component's
constructor."

**
Martin

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


Re: Make sure you are not calling Component#getString() inside your Component's constructor.

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Ah.. ok. It [StringResourceModel] just feels so much like a waste I
have forgotten about it ;) Tnx.

**
Martin

2009/7/25 Per Newgro <pe...@gmx.ch>:
> Martin Makundi schrieb:
>>
>> Or what is the best-practice to avoid these warnings: "Make sure you
>> are not calling Component#getString() inside your Component's
>> constructor."
>>
>
> I would use a StringResourceModel. Then the value for getString will be used
> in rendering not at
> construction time.
>
> XYZComponent extends xxx  {
>
>   public XYZComponent(String id) {
>       add(new Label("idxyz", new StringResourceModel("localized_label"));
>      //Sometimes like this, sometimes just using <wicket:message key="xyz"/>
>   }
> }
>
> Cheers
> Per
>
>
> ---------------------------------------------------------------------
> 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: Make sure you are not calling Component#getString() inside your Component's constructor.

Posted by Per Newgro <pe...@gmx.ch>.
Martin Makundi schrieb:
> Or what is the best-practice to avoid these warnings: "Make sure you
> are not calling Component#getString() inside your Component's
> constructor."
>   
I would use a StringResourceModel. Then the value for getString will be 
used in rendering not at
construction time.

XYZComponent extends xxx  {

    public XYZComponent(String id) {
        add(new Label("idxyz", new StringResourceModel("localized_label")); 
	//Sometimes like this, sometimes just using <wicket:message key="xyz"/>
    }
}

Cheers
Per


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