Re: Convert a null Model to a custom string rather than

2009-01-28 Thread Anton Veretennikov
But it throws Internal Error (not in feedback) when conversion
error rises on this line:

mNestedModel.setObject(object);

So it will be nice to correct it somehow..


Example of error on BigDecimal:

ERROR - RequestCycle   - Cannot parse '2.5' using format
java.text.decimalfor...@674dc
org.apache.wicket.util.convert.ConversionException: Cannot parse '2.5'
using format java.text.decimalfor...@674dc
at 
org.apache.wicket.util.convert.converters.AbstractConverter.newConversionException(AbstractConverter.java:78)
at 
org.apache.wicket.util.convert.converters.AbstractConverter.parse(AbstractConverter.java:58)
at 
org.apache.wicket.util.convert.converters.AbstractNumberConverter.parse(AbstractNumberConverter.java:80)
at 
org.apache.wicket.util.convert.converters.BigDecimalConverter.convertToObject(BigDecimalConverter.java:43)
at 
org.apache.wicket.util.convert.converters.BigDecimalConverter.convertToObject(BigDecimalConverter.java:28)
at 
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyResolverConverter.java:68)
at 
org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(PropertyResolver.java:1082)
at 
org.apache.wicket.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:582)
at 
org.apache.wicket.util.lang.PropertyResolver.setValue(PropertyResolver.java:136)
at 
org.apache.wicket.model.AbstractPropertyModel.setObject(AbstractPropertyModel.java:169)
at 
common.component.DefaultWhenNullModel.setObject(DefaultWhenNullModel.java:41)


On Wed, Jan 28, 2009 at 11:51 AM, Anton Veretennikov
anton.veretenni...@gmail.com wrote:
 Not very nice but works (Jeremy Thomerson's variant with setObject changes):

 public class DefaultWhenNullModelT implements IModelT {

  private static final long serialVersionUID = 1L;
  private final IModelT mNestedModel;
  private final T mDefaultValue;

  public DefaultWhenNullModel(IModelT nestedModel, T defaultValue) {
mNestedModel = nestedModel;
mDefaultValue = defaultValue;
  }

  public T getObject() {
T val = mNestedModel.getObject();
return val == null ? mDefaultValue : val;
  }

  public void setObject(T object) {
if (object!=null  object.equals(mDefaultValue)) {
  mNestedModel.setObject(null);
} else {
  mNestedModel.setObject(object);
}
  }

  public void detach() {
mNestedModel.detach();
  }
 }


 Usage:
form.add(new TextField(value,
new DefaultWhenNullModel(new
 PropertyModel(getSomeModel(),value), Enter a value)

));




 On Wed, Jan 28, 2009 at 5:16 AM, nate roe phl...@gmail.com wrote:
 Actually, I don't think that this will work for me.

 The behavior that I want is to display a special string when the model is
 null.  However, I still want the model to be null.

 My custom converter converts a special keyword to a null model.  I want also
 to convert a new model to a special keyword for display.

 On Tue, Jan 27, 2009 at 11:46 AM, nate roe phl...@gmail.com wrote:

 Excellent, thanks for writing that one up!


 On Tue, Jan 27, 2009 at 11:41 AM, Jeremy Thomerson 
 jer...@wickettraining.com wrote:

 This has come up quite a bit here on the user list.

 See the first example on this page:

 http://www.jeremythomerson.com/blog/2008/11/06/wicket-the-power-of-nested-models/


 --
 Jeremy Thomerson
 http://www.wickettraining.com

 On Tue, Jan 27, 2009 at 1:38 PM, nate roe phl...@gmail.com wrote:

  I'm using Wicket v1.3.4.
 
  I would like to create a kind of TextField that converts a null model
 value
  to a custom string rather than an empty string.  Unfortunately, the
  converter is not run when the model object is null, and it looks like
  Component.getModelObjectAsString(...) is hard-coded to return  when
 the
  model is null.
 
  Is there some way I can overcome this without modifying the Wicket
 source?
 
  Thanks,
  Nate Roe
 






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



Convert a null Model to a custom string rather than

2009-01-27 Thread nate roe
I'm using Wicket v1.3.4.

I would like to create a kind of TextField that converts a null model value
to a custom string rather than an empty string.  Unfortunately, the
converter is not run when the model object is null, and it looks like
Component.getModelObjectAsString(...) is hard-coded to return  when the
model is null.

Is there some way I can overcome this without modifying the Wicket source?

Thanks,
Nate Roe


Re: Convert a null Model to a custom string rather than

2009-01-27 Thread Jeremy Thomerson
This has come up quite a bit here on the user list.

See the first example on this page:
http://www.jeremythomerson.com/blog/2008/11/06/wicket-the-power-of-nested-models/


-- 
Jeremy Thomerson
http://www.wickettraining.com

On Tue, Jan 27, 2009 at 1:38 PM, nate roe phl...@gmail.com wrote:

 I'm using Wicket v1.3.4.

 I would like to create a kind of TextField that converts a null model value
 to a custom string rather than an empty string.  Unfortunately, the
 converter is not run when the model object is null, and it looks like
 Component.getModelObjectAsString(...) is hard-coded to return  when the
 model is null.

 Is there some way I can overcome this without modifying the Wicket source?

 Thanks,
 Nate Roe



Re: Convert a null Model to a custom string rather than

2009-01-27 Thread nate roe
Excellent, thanks for writing that one up!

On Tue, Jan 27, 2009 at 11:41 AM, Jeremy Thomerson 
jer...@wickettraining.com wrote:

 This has come up quite a bit here on the user list.

 See the first example on this page:

 http://www.jeremythomerson.com/blog/2008/11/06/wicket-the-power-of-nested-models/


 --
 Jeremy Thomerson
 http://www.wickettraining.com

 On Tue, Jan 27, 2009 at 1:38 PM, nate roe phl...@gmail.com wrote:

  I'm using Wicket v1.3.4.
 
  I would like to create a kind of TextField that converts a null model
 value
  to a custom string rather than an empty string.  Unfortunately, the
  converter is not run when the model object is null, and it looks like
  Component.getModelObjectAsString(...) is hard-coded to return  when the
  model is null.
 
  Is there some way I can overcome this without modifying the Wicket
 source?
 
  Thanks,
  Nate Roe
 



Re: Convert a null Model to a custom string rather than

2009-01-27 Thread nate roe
Actually, I don't think that this will work for me.

The behavior that I want is to display a special string when the model is
null.  However, I still want the model to be null.

My custom converter converts a special keyword to a null model.  I want also
to convert a new model to a special keyword for display.

On Tue, Jan 27, 2009 at 11:46 AM, nate roe phl...@gmail.com wrote:

 Excellent, thanks for writing that one up!


 On Tue, Jan 27, 2009 at 11:41 AM, Jeremy Thomerson 
 jer...@wickettraining.com wrote:

 This has come up quite a bit here on the user list.

 See the first example on this page:

 http://www.jeremythomerson.com/blog/2008/11/06/wicket-the-power-of-nested-models/


 --
 Jeremy Thomerson
 http://www.wickettraining.com

 On Tue, Jan 27, 2009 at 1:38 PM, nate roe phl...@gmail.com wrote:

  I'm using Wicket v1.3.4.
 
  I would like to create a kind of TextField that converts a null model
 value
  to a custom string rather than an empty string.  Unfortunately, the
  converter is not run when the model object is null, and it looks like
  Component.getModelObjectAsString(...) is hard-coded to return  when
 the
  model is null.
 
  Is there some way I can overcome this without modifying the Wicket
 source?
 
  Thanks,
  Nate Roe
 





Re: Convert a null Model to a custom string rather than

2009-01-27 Thread Anton Veretennikov
Not very nice but works (Jeremy Thomerson's variant with setObject changes):

public class DefaultWhenNullModelT implements IModelT {

  private static final long serialVersionUID = 1L;
  private final IModelT mNestedModel;
  private final T mDefaultValue;

  public DefaultWhenNullModel(IModelT nestedModel, T defaultValue) {
mNestedModel = nestedModel;
mDefaultValue = defaultValue;
  }

  public T getObject() {
T val = mNestedModel.getObject();
return val == null ? mDefaultValue : val;
  }

  public void setObject(T object) {
if (object!=null  object.equals(mDefaultValue)) {
  mNestedModel.setObject(null);
} else {
  mNestedModel.setObject(object);
}
  }

  public void detach() {
mNestedModel.detach();
  }
}


Usage:
form.add(new TextField(value,
new DefaultWhenNullModel(new
PropertyModel(getSomeModel(),value), Enter a value)

));




On Wed, Jan 28, 2009 at 5:16 AM, nate roe phl...@gmail.com wrote:
 Actually, I don't think that this will work for me.

 The behavior that I want is to display a special string when the model is
 null.  However, I still want the model to be null.

 My custom converter converts a special keyword to a null model.  I want also
 to convert a new model to a special keyword for display.

 On Tue, Jan 27, 2009 at 11:46 AM, nate roe phl...@gmail.com wrote:

 Excellent, thanks for writing that one up!


 On Tue, Jan 27, 2009 at 11:41 AM, Jeremy Thomerson 
 jer...@wickettraining.com wrote:

 This has come up quite a bit here on the user list.

 See the first example on this page:

 http://www.jeremythomerson.com/blog/2008/11/06/wicket-the-power-of-nested-models/


 --
 Jeremy Thomerson
 http://www.wickettraining.com

 On Tue, Jan 27, 2009 at 1:38 PM, nate roe phl...@gmail.com wrote:

  I'm using Wicket v1.3.4.
 
  I would like to create a kind of TextField that converts a null model
 value
  to a custom string rather than an empty string.  Unfortunately, the
  converter is not run when the model object is null, and it looks like
  Component.getModelObjectAsString(...) is hard-coded to return  when
 the
  model is null.
 
  Is there some way I can overcome this without modifying the Wicket
 source?
 
  Thanks,
  Nate Roe
 





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