Re: java.util.Properties as Form Model
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 wrote: > An idea is to wrap the Properties object in a class of your own > implementing Map as follows: > > class MyProps implements Map { > 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.vandenheu...@gmail.com> wrote: > > > Hey, > > > > I'm trying to create a form with a CompoundPropertyModel to fill a > > java.util.Properties object dynamically. > > > > Form form = new Form<>("form", new > > CompoundPropertyModel<>(properties)); > > form.add(new TextField("host")); > > form.add(new TextField("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
An idea is to wrap the Properties object in a class of your own implementing Map as follows: class MyProps implements Map { 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.vandenheu...@gmail.com> wrote: > Hey, > > I'm trying to create a form with a CompoundPropertyModel to fill a > java.util.Properties object dynamically. > > Form form = new Form<>("form", new > CompoundPropertyModel<>(properties)); > form.add(new TextField("host")); > form.add(new TextField("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! >
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 form = new Form<>("form", new CompoundPropertyModel<>(properties)); form.add(new TextField("host")); form.add(new TextField("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!