not sure DecimalFormat is really serializable. Format is, but
DecimalFormat's DigitList is not....

-igor


On Thu, Sep 22, 2011 at 1:45 PM, Pranav kacholia
<pranav.kacho...@gmail.com> wrote:
> I have foound many places where i need to format a number and display it in a
> label. Can we have a simple child of Label as follows which can be used to
> do the same?
>
> ------------------------------------------------------------
> package ;
>
> import java.text.DecimalFormat;
> 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 DecimalFormatLabel extends Label {
>
>    final private DecimalFormat formatter;
>
>    public DecimalFormatLabel(String id, IModel<? extends Number> model,
> DecimalFormat format) {
>        super(id, model);
>        formatter = format;
>    }
>
>    public DecimalFormatLabel(String id, Number obj, DecimalFormat format) {
>        this(id, new Model<Number>(obj), format);
>    }
>
>    public DecimalFormatLabel(String id, DecimalFormat 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-tp3834813p3834813.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
>
>

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

Reply via email to