Or we go one step further back. I think this would handle all use cases. If
we want to put in a NumberFormat or a DecimalFormat , in both cases it
should work.


public class FormattedLabel extends Label{
    
    final private Format formatter;
    
    public FormattedLabel(String id, IModel<? extends Number> model, Format
format) {
        super(id, model);
        formatter = format;
    }

    public FormattedLabel(String id, Number obj, Format format) {
        this(id, new Model<Number>(obj), format);
    }

    public FormattedLabel(String id, Format 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("Format"));
            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-tp3834813p3837336.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

Reply via email to