You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Stefan Lindner <li...@visionet.de> on 2007/03/06 11:01:47 UTC

Shouldn't wicket.markup.html.basic.Label extend WebComponent?

In Wicket 2 the Label class is defined as
 
     public class Label extends WebComponent
 
The Label class inhertis setModelObject from Comonent<T> through the genetric class WebComponent<T>.
The method
 
     public final Component setModelObject(final T object)
 
is generic too.
 
Now If we have code like
 
     Label l = new Label(this, "label", "The label's modelObject");
     l.setModelObject("The new modelObject");
 
alway leads to a warning like
 
     the method setModelObject belongs to the raw type Component...
 
Declaring Label like
 
     public class Label extends WebComponent<String>
 
would remove the warning and should not affect any part of wicket. Or am I wrong?
 
Stefan Lindner

RE: Shouldn't wicket.markup.html.basic.Label extend WebComponent?

Posted by Stefan Lindner <li...@visionet.de>.
Shall I create an issue or will this be fixed en passant? Appended is a version ov Label that I testes with the current svn version of wicket 2.0
 
Stefan Lindner
 
 
 
------ The code without the license header ------------
package wicket.markup.html.basic;
import wicket.MarkupContainer;
import wicket.markup.ComponentTag;
import wicket.markup.MarkupStream;
import wicket.markup.html.WebComponent;
import wicket.model.IModel;
import wicket.model.Model;
/**
 * A Label component replaces its body with the String version of its model
 * object returned by getModelObjectAsString().
 * <p>
 * Exactly what is displayed as the body, depends on the model. The simplest
 * case is a Label with a static String model, which can be constructed like
 * this:
 *
 * <pre>
 * add(new Label<String>(&quot;myLabel&quot;, &quot;the string to display&quot;))
 * </pre>
 *
 * A Label with a dynamic model can be created like this:
 *
 * <pre>
 *
 *             add(new Label<String>(&quot;myLabel&quot;, new PropertyModel<String>(person, &quot;name&quot;));
 *
 * </pre>
 *
 * In this case, the Label component will replace the body of the tag it is
 * attached to with the 'name' property of the given Person object, where Person
 * might look like:
 *
 * <pre>
 * public class Person
 * {
 *  private String name;
 *
 *  public String getName()
 *  {
 *   return name;
 *  }
 *
 *  public void setName(String name)
 *  {
 *   this.name = name;
 *  }
 * }
 * </pre>
 *
 * @author Jonathan Locke
 */
public class Label<T> extends WebComponent<T>
{
 private static final long serialVersionUID = 1L;
 /**
  * Constructor
  *
  * @param parent
  *            The parent of this component
  *
  * @param id
  *            See Component
  */
 public Label(MarkupContainer parent, final String id)
 {
  super(parent, id);
 }
 /**
  * Convenience constructor. Same as Label(String, new Model(String))
  *
  * @param parent
  *            The parent of this component The parent component
  *
  * @param id
  *            See Component
  * @param label
  *            The label text
  *
  * @see wicket.Component#Component(MarkupContainer,String, IModel)
  */
 public Label(MarkupContainer parent, final String id, String label)
 {
  this(parent, id, new Model<String>(label));
 }
 /**
  * @see wicket.Component#Component(MarkupContainer, String, IModel)
  */
 @SuppressWarnings("unchecked")
 public Label(MarkupContainer parent, final String id, IModel<T> model)
 {
  super(parent, id, model);
 }
 /**
  * @see wicket.Component#onComponentTagBody(wicket.markup.MarkupStream,
  *      wicket.markup.ComponentTag)
  */
 @Override
 protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag)
 {
  replaceComponentTagBody(markupStream, openTag, getModelObjectAsString());
 }
}

Re: Shouldn't wicket.markup.html.basic.Label extend WebComponent?

Posted by Johan Compagner <jc...@gmail.com>.
Yes label model object is not used just for strings so it should be Label<T>

johan


On 3/6/07, Martin Benda <be...@bendis.cz> wrote:
>
> Hi,
>
> a Label can have a model of any type, so that you can easily display
> Dates,
> Booleans, Numbers and so on... IConverters (via getModelObjectAsString()
> call) are responsible for converting these model objects to displayable
> strings in a locale-sensitive manner.
>
> So "public class Label extends WebComponent<String>" would be wrong...
>
> IMHO, Label should be type parameterized itself, extending a raw type is
> unsafe.
>
> public class Label<T> extends WebComponent<T>
> {
>         ...
>
>         public Label(MarkupContainer parent, final String id, T label)
>         {
>                 this(parent, id, Model.valueOf(label));
>         }
>
>         public Label(MarkupContainer parent, final String id, IModel<T>
> model)
>         {
>                 super(parent, id, model);
>         }
>
>         ...
> }
>
> The raw type Label can be still used if desired...
>
> What do the wicket developers think?
>
> Regards,
> Bendis
>
> On Tuesday 06 of March 2007 11:01:47 Stefan Lindner wrote:
> > In Wicket 2 the Label class is defined as
> >
> >      public class Label extends WebComponent
> >
> > The Label class inhertis setModelObject from Comonent<T> through the
> > genetric class WebComponent<T>. The method
> >
> >      public final Component setModelObject(final T object)
> >
> > is generic too.
> >
> > Now If we have code like
> >
> >      Label l = new Label(this, "label", "The label's modelObject");
> >      l.setModelObject("The new modelObject");
> >
> > alway leads to a warning like
> >
> >      the method setModelObject belongs to the raw type Component...
> >
> > Declaring Label like
> >
> >      public class Label extends WebComponent<String>
> >
> > would remove the warning and should not affect any part of wicket. Or am
> I
> > wrong?
> >
> > Stefan Lindner
>
>
>

Re: Shouldn't wicket.markup.html.basic.Label extend WebComponent?

Posted by Martin Benda <be...@bendis.cz>.
Hi,

a Label can have a model of any type, so that you can easily display Dates, 
Booleans, Numbers and so on... IConverters (via getModelObjectAsString() 
call) are responsible for converting these model objects to displayable 
strings in a locale-sensitive manner.

So "public class Label extends WebComponent<String>" would be wrong...

IMHO, Label should be type parameterized itself, extending a raw type is 
unsafe.

public class Label<T> extends WebComponent<T>
{
        ...

	public Label(MarkupContainer parent, final String id, T label)
	{
		this(parent, id, Model.valueOf(label));
	}

	public Label(MarkupContainer parent, final String id, IModel<T> model)
	{
		super(parent, id, model);
	}

        ...
}

The raw type Label can be still used if desired...

What do the wicket developers think?

Regards,
Bendis

On Tuesday 06 of March 2007 11:01:47 Stefan Lindner wrote:
> In Wicket 2 the Label class is defined as
>
>      public class Label extends WebComponent
>
> The Label class inhertis setModelObject from Comonent<T> through the
> genetric class WebComponent<T>. The method
>
>      public final Component setModelObject(final T object)
>
> is generic too.
>
> Now If we have code like
>
>      Label l = new Label(this, "label", "The label's modelObject");
>      l.setModelObject("The new modelObject");
>
> alway leads to a warning like
>
>      the method setModelObject belongs to the raw type Component...
>
> Declaring Label like
>
>      public class Label extends WebComponent<String>
>
> would remove the warning and should not affect any part of wicket. Or am I
> wrong?
>
> Stefan Lindner