Suppose someone wants to call formatlLabel.getModelObject() ... I don’t see why they would, but hypothetically.
In this case you would get the formatted string. Since the label is merely a view, should it be changing the model even by formatting it? From: Yves-Marie LAINÉ [via Apache Wicket] [mailto:ml-node+s1842946n3837008...@n4.nabble.com] Sent: 23 September 2011 19:57 To: Pranav kacholia Subject: Re: DecimalFormatLabel (proposed) Hi all, Personnaly I did it like that (simpler for i18n, i think) : public class FormatLabel extends Label { public FormatLabel(String id,final String formatKey, final IModel<? extends Serializable> model) { super (id); setDefaultModel(new AbstractReadOnlyModel<String>() { @Override public String getObject() { Serializable o = model.getObject(); if ( o != null) { return new StringResourceModel(formatKey, FormatLabel.this, model, new Object[]{o}).getObject(); } return getString(FormatLabel.this.getId() + ".null"); } }); } } Yves-Marie 2011/9/23 Pranav kacholia <[hidden email]> > Perhaps we can keep it as a NumberFormatLabel for greater flexibility > > import java.text.NumberFormat; > import org.apache.wicket.markup.ComponentTag; > import org.apache.wicket.markup.MarkupStream; > import org.apache.wicket.markup.html.basic.Label; > import org.apache.wicket.model.IModel; > import org.apache.wicket.model.Model; > > /** > * > * @author pkacholia > */ > public class NumberFormatLabel extends Label { > > final private NumberFormat formatter; > > public NumberFormatLabel(String id, IModel<? extends Number> model, > NumberFormat format) { > super(id, model); > formatter = format; > } > > public NumberFormatLabel(String id, Number obj, NumberFormat format) { > this(id, new Model<Number>(obj), format); > } > > public NumberFormatLabel(String id, NumberFormat format) { > super(id); > formatter = format; > } > > /** > * {@inheritDoc} > */ > @Override > public void onComponentTagBody(final MarkupStream markupStream, final > ComponentTag openTag) { > String response; > try { > response = formatter.format(getDefaultModelObject()); > } catch (IllegalArgumentException ex) { > error(getString("NaN")); > response = ""; > } catch (NullPointerException ex) { > error(getString("NullFormatter")); > response = ""; > } > replaceComponentTagBody(markupStream, openTag, response); > } > } > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3836001.html > Sent from the Users forum mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > -- Yves-Marie LAINÉ _____ If you reply to this email, your message will be added to the discussion below: http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3837008.html To unsubscribe from DecimalFormatLabel (proposed), click <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=3834813&code=cHJhbmF2LmthY2hvbGlhQGdtYWlsLmNvbXwzODM0ODEzfC0yMDAxMDYyNzM1> here. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3837115.html Sent from the Users forum mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org