You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Andy Van Den Heuvel <an...@gmail.com> on 2013/10/18 12:55:10 UTC
java.util.Properties as Form Model
Hey,
I'm trying to create a form with a CompoundPropertyModel to fill a
java.util.Properties object dynamically.
Form<Properties> form = new Form<>("form", new
CompoundPropertyModel<>(properties));
form.add(new TextField<String>("host"));
form.add(new TextField<String>("port"));
This works correct when I start from an empty java.util.Properties object.
If I have an existing java.util.Properties object (with filled data)
and I remove the value in the html page, I want the key-value pair to be
deleted from the Properties object.
With my current implementation I get a stacktrace (because it tries to
write a null value in the java.util.Properties object)
java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:432)
at
org.apache.wicket.core.util.lang.PropertyResolver$MapGetSet.setValue(PropertyResolver.java:803)
at
org.apache.wicket.core.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:644)
at
org.apache.wicket.core.util.lang.PropertyResolver.setValue(PropertyResolver.java:144)
Has anybody have an idea how best to create this behaviour?
Thanks in advance for your help!
Re: java.util.Properties as Form Model
Posted by Andy Van Den Heuvel <an...@gmail.com>.
This indeed solves the trick. I'm not sure this is a bug, since the
propertyresolver is a general system and Hashtable is just an exception to
normal javabean rules.
On Fri, Oct 18, 2013 at 2:01 PM, Marios Skounakis <ms...@gmail.com> wrote:
> An idea is to wrap the Properties object in a class of your own
> implementing Map as follows:
>
> class MyProps implements Map<String, String> {
> Properties props;
>
> public void put(String key, String value) {
> if (value == null) props.remove(key);
> else props.put(key, value);
> }
>
> This does sound like a bug in PropertyResolver as it should probably test
> whether the Map is a Hashtable and call remove() since Hashtable is
> documented to throw an NPE when put() is called with a null value.
>
>
>
> On Fri, Oct 18, 2013 at 1:55 PM, Andy Van Den Heuvel <
> andy.vandenheuvel@gmail.com> wrote:
>
> > Hey,
> >
> > I'm trying to create a form with a CompoundPropertyModel to fill a
> > java.util.Properties object dynamically.
> >
> > Form<Properties> form = new Form<>("form", new
> > CompoundPropertyModel<>(properties));
> > form.add(new TextField<String>("host"));
> > form.add(new TextField<String>("port"));
> >
> > This works correct when I start from an empty java.util.Properties
> object.
> > If I have an existing java.util.Properties object (with filled data)
> > and I remove the value in the html page, I want the key-value pair to be
> > deleted from the Properties object.
> >
> > With my current implementation I get a stacktrace (because it tries to
> > write a null value in the java.util.Properties object)
> >
> > java.lang.NullPointerException
> > at java.util.Hashtable.put(Hashtable.java:432)
> > at
> >
> >
> org.apache.wicket.core.util.lang.PropertyResolver$MapGetSet.setValue(PropertyResolver.java:803)
> > at
> >
> >
> org.apache.wicket.core.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:644)
> > at
> >
> >
> org.apache.wicket.core.util.lang.PropertyResolver.setValue(PropertyResolver.java:144)
> >
> >
> > Has anybody have an idea how best to create this behaviour?
> > Thanks in advance for your help!
> >
>
Re: java.util.Properties as Form Model
Posted by Marios Skounakis <ms...@gmail.com>.
An idea is to wrap the Properties object in a class of your own
implementing Map as follows:
class MyProps implements Map<String, String> {
Properties props;
public void put(String key, String value) {
if (value == null) props.remove(key);
else props.put(key, value);
}
This does sound like a bug in PropertyResolver as it should probably test
whether the Map is a Hashtable and call remove() since Hashtable is
documented to throw an NPE when put() is called with a null value.
On Fri, Oct 18, 2013 at 1:55 PM, Andy Van Den Heuvel <
andy.vandenheuvel@gmail.com> wrote:
> Hey,
>
> I'm trying to create a form with a CompoundPropertyModel to fill a
> java.util.Properties object dynamically.
>
> Form<Properties> form = new Form<>("form", new
> CompoundPropertyModel<>(properties));
> form.add(new TextField<String>("host"));
> form.add(new TextField<String>("port"));
>
> This works correct when I start from an empty java.util.Properties object.
> If I have an existing java.util.Properties object (with filled data)
> and I remove the value in the html page, I want the key-value pair to be
> deleted from the Properties object.
>
> With my current implementation I get a stacktrace (because it tries to
> write a null value in the java.util.Properties object)
>
> java.lang.NullPointerException
> at java.util.Hashtable.put(Hashtable.java:432)
> at
>
> org.apache.wicket.core.util.lang.PropertyResolver$MapGetSet.setValue(PropertyResolver.java:803)
> at
>
> org.apache.wicket.core.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:644)
> at
>
> org.apache.wicket.core.util.lang.PropertyResolver.setValue(PropertyResolver.java:144)
>
>
> Has anybody have an idea how best to create this behaviour?
> Thanks in advance for your help!
>