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: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to