Re: DecimalFormatLabel (proposed)

2011-09-27 Thread Pranav kacholia
Updated the patch and resubmitted.

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3847952.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



Re: DecimalFormatLabel (proposed)

2011-09-27 Thread Igor Vaynberg
wrap it in a wicket runtime exception

-igor


On Tue, Sep 27, 2011 at 6:32 AM, Pranav kacholia
 wrote:
> I have submitted a patch  https://issues.apache.org/jira/browse/WICKET-4085
> Wicket-4085 . for a formatted label.
>
> I cant figure what would be the best way to handle an
> IllegalArgumentException which is thrown when the supplied format object in
> not valid for the underlying data object.
>
>
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3847356.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



Re: DecimalFormatLabel (proposed)

2011-09-27 Thread Pranav kacholia
I have submitted a patch  https://issues.apache.org/jira/browse/WICKET-4085
Wicket-4085 . for a formatted label. 

I cant figure what would be the best way to handle an
IllegalArgumentException which is thrown when the supplied format object in
not valid for the underlying data object. 


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3847356.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



Re: DecimalFormatLabel (proposed)

2011-09-26 Thread Yves-Marie LAINÉ
I agree with you.

Yves-Marie

2011/9/25 Pranav kacholia 

> One way or the other, i think Wicket needs a label of that sort.
> There are too many places where i have to display currency. It should have
> something inbuilt that allows us to display formatted strings and numbers
> (a
> label)
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3840944.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
>
>


-- 
Yves-Marie LAINÉ


Re: DecimalFormatLabel (proposed)

2011-09-25 Thread Pranav kacholia
One way or the other, i think Wicket needs a label of that sort. 
There are too many places where i have to display currency. It should have
something inbuilt that allows us to display formatted strings and numbers (a
label)


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3840944.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



Re: DecimalFormatLabel (proposed)

2011-09-23 Thread Yves-Marie LAINÉ
In my opinion, it could be more usefull to nest  a StringResourceModel
directly in a "ResourceLabel", as formating number is often application wide
and sometimes  Locale dependent. And it covers more use case. It's just my
point of view.

Maybe like this :
protected void onComponentTagBody(final MarkupStream markupStream, final
ComponentTag openTag)
{
replaceComponentTagBody(markupStream, openTag, new
StringResourceModel(formatKey, this, getDefaultModel(), new
Object[]{getDefaultModelObject()}, defaultValue));
}



2011/9/23 Pranav kacholia 

> 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 model, Format
> format) {
>super(id, model);
>formatter = format;
>}
>
> public FormattedLabel(String id, Number obj, Format format) {
> this(id, new Model(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
>
>


-- 
Yves-Marie LAINÉ


Re: DecimalFormatLabel (proposed)

2011-09-23 Thread Pranav kacholia
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 model, Format
format) {
super(id, model);
formatter = format;
}

public FormattedLabel(String id, Number obj, Format format) {
this(id, new Model(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



Re: DecimalFormatLabel (proposed)

2011-09-23 Thread Yves-Marie LAINÉ
Yes, you're right, but this way fit 90% of my needs (It's a Label...)

Otherwise, it's possible to use a CustomConverter to do it, and then
override getConverter on Component. So, it also work on TextField (but i
agree, it's not exactly your use case. ) :

@Override
public IConverter getConverter(Class type) {

return PercentConverter.INSTANCE_2DEC;
}

public class PercentConverter extends AbstractNumberConverter {

public static final PercentConverter INSTANCE = new PercentConverter();

public static final PercentConverter INSTANCE_2DEC = new
PercentConverter() {
public NumberFormat getNumberFormat(Locale locale) {
NumberFormat nf = DecimalFormat.getPercentInstance(locale);
nf.setMinimumFractionDigits(2);
nf.setMaximumFractionDigits(2);
return nf;
};
};

public static final PercentConverter INSTANCE_4DEC = new
PercentConverter() {
public NumberFormat getNumberFormat(Locale locale) {
NumberFormat nf = DecimalFormat.getPercentInstance(locale);
nf.setMinimumFractionDigits(4);
nf.setMaximumFractionDigits(4);
return nf;
};
};

public Object convertToObject(String value, Locale locale) {
if (value == null)
return null;

value = value.trim();
if (value.trim().equals(""))
{
return null;
}

Number n = null;
try {
n =  getNumberFormat(locale).parse(value);
} catch (ParseException e) {
throw newConversionException(e.getMessage(), value,
locale).setFormat(
getNumberFormat(locale));

}

return n.floatValue();
}

@Override
protected Class getTargetType() {
return Float.class;
}

@Override
public NumberFormat getNumberFormat(Locale locale) {
return NumberFormat.getPercentInstance(locale);
}

}






2011/9/23 Pranav kacholia 

> 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() {
>@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 model,
> > NumberFormat format) {
> > super(id, model);
> >formatter = format;
> >}
> >
> > public NumberFormatLabel(String id, Number obj, NumberFormat format)
> {
> > this(id, new Model(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) {
> > 

RE: DecimalFormatLabel (proposed)

2011-09-23 Thread Pranav kacholia
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 model) { 
super (id); 
setDefaultModel(new AbstractReadOnlyModel() { 
@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 model, 
> NumberFormat format) { 
> super(id, model); 
>formatter = format; 
>} 
> 
> public NumberFormatLabel(String id, Number obj, NumberFormat format) { 
> this(id, new Model(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



Re: DecimalFormatLabel (proposed)

2011-09-23 Thread Yves-Marie LAINÉ
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 model) {
super (id);
setDefaultModel(new AbstractReadOnlyModel() {
@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 

> 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 model,
> NumberFormat format) {
> super(id, model);
>formatter = format;
>}
>
> public NumberFormatLabel(String id, Number obj, NumberFormat format) {
> this(id, new Model(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
>
>


-- 
Yves-Marie LAINÉ


RE: DecimalFormatLabel (proposed)

2011-09-23 Thread Pranav kacholia
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 model,
NumberFormat format) {
super(id, model);
formatter = format;
}

public NumberFormatLabel(String id, Number obj, NumberFormat format) {
this(id, new Model(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



RE: DecimalFormatLabel (proposed)

2011-09-22 Thread Pranav kacholia
I figured this would work best if we use things like CompoundPropertyModel. 

 

Imagine you have a property of type int called myInt  in POJO called myPojo

 

Then the code becomes extremely simple 

 

WebMarkupContainer container = new WebMarkupContainer("container", new
CompoundPropertyModel(myPojo));

container.add(new DecimalFormatLabel("myInt", new DecimalFormat());

 

 

 

From: uiron [via Apache Wicket]
[mailto:ml-node+s1842946n383594...@n4.nabble.com] 
Sent: 23 September 2011 12:17
To: Pranav kacholia
Subject: Re: DecimalFormatLabel (proposed)

 

Wouldn't it be better to create a model of String type which is 
constructed with a Number and NumberFormat as arguments, and use it as 
model for standard label? 

On 2011.09.22 23:45, Pranav kacholia 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  model,

> DecimalFormat format) { 
>  super(id, model); 
>  formatter = format; 
>  } 
> 
>  public DecimalFormatLabel(String id, Number obj, DecimalFormat
format) { 
>  this(id, new Model(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-tp383
4813p3834813.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] 
> 



- 
To unsubscribe, e-mail: [hidden email] 
For additional commands, e-mail: [hidden email] 




  _  

If you reply to this email, your message will be added to the discussion
below:

http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp383
4813p3835944.html 

To unsubscribe from DecimalFormatLabel (proposed), click
<http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=u
nsubscribe_by_code&node=3834813&code=cHJhbmF2LmthY2hvbGlhQGdtYWlsLmNvbXwzODM
0ODEzfC0yMDAxMDYyNzM1>  here. 



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3835958.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



Re: DecimalFormatLabel (proposed)

2011-09-22 Thread Viktoras
Wouldn't it be better to create a model of String type which is 
constructed with a Number and NumberFormat as arguments, and use it as 
model for standard label?


On 2011.09.22 23:45, Pranav kacholia 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  model,
DecimalFormat format) {
 super(id, model);
 formatter = format;
 }

 public DecimalFormatLabel(String id, Number obj, DecimalFormat format) {
 this(id, new Model(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



Re: DecimalFormatLabel (proposed)

2011-09-22 Thread Igor Vaynberg
yeah, transient fields are ok...

-igor


On Thu, Sep 22, 2011 at 2:20 PM, Pranav kacholia
 wrote:
> Looking over the sourcecode of DecimalFormat (Java 6) there are a few fields
> which do not implements Serializable.
> Those are all of type DigitList and FieldPosition.
>
> however, in all the cases they are marked as Transient, so they shouldnt
> interfere with the serialization?
>
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3834903.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



Re: DecimalFormatLabel (proposed)

2011-09-22 Thread Pranav kacholia
Looking over the sourcecode of DecimalFormat (Java 6) there are a few fields
which do not implements Serializable. 
Those are all of type DigitList and FieldPosition. 

however, in all the cases they are marked as Transient, so they shouldnt
interfere with the serialization?

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3834903.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



Re: DecimalFormatLabel (proposed)

2011-09-22 Thread Pranav kacholia
I have been using it since earlier today. Havent seen any exceptions thrown. 
Im relatively new to wicket , so what should i look out for in case it isnt
actually serializable? 

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/DecimalFormatLabel-proposed-tp3834813p3834847.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



Re: DecimalFormatLabel (proposed)

2011-09-22 Thread Igor Vaynberg
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
 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 model,
> DecimalFormat format) {
>        super(id, model);
>        formatter = format;
>    }
>
>    public DecimalFormatLabel(String id, Number obj, DecimalFormat format) {
>        this(id, new Model(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