Revision history [back]

click to hide/show revision 1
initial version

answered 2016-04-20 06:06:31 +0800

cor3000 gravatar image cor3000

ZK Team

A helper class is not needed when giving the method a name that does not start with get... The formproxy will intercept methods starting with get/set/is (other methods call through to the original object) e.g.

public SubSubBean ensureSubSubBean(String key) {
    SubSubBean subSubBean = getSubSubBeans().get(key);
    if (subSubBean == null) {
        subSubBean = new SubSubBean();
        getSubSubBeans().put(key, subSubBean);
    }
    return subSubBean;
}

(as Chill pointed out correctly: access the map using the getSubSubBeans() method to modify the proxied map)


and in case tired of writing if(map.contains(...)) {map.put(.., new Bean...)} you can use map.computeIfAbsent(...) java 8 to streamline this a lot:

public SubSubBean ensureSubSubBean(String key) {
    return getSubSubBeans().computeIfAbsent(key, k -> new SubSubBean());
}

Isn't that a beauty ;)

A helper class is not needed when giving the method a name that does not start with get... (or mark it @Transient) The formproxy will intercept methods starting with get/set/is (other methods call through to the original object) e.g.

public SubSubBean ensureSubSubBean(String key) {
    SubSubBean subSubBean = getSubSubBeans().get(key);
    if (subSubBean == null) {
        subSubBean = new SubSubBean();
        getSubSubBeans().put(key, subSubBean);
    }
    return subSubBean;
}

(as Chill pointed out correctly: access the map using the getSubSubBeans() method to modify the proxied map)


and in case tired of writing if(map.contains(...)) {map.put(.., new Bean...)} you can use map.computeIfAbsent(...) java 8 to streamline this a lot:

public SubSubBean ensureSubSubBean(String key) {
    return getSubSubBeans().computeIfAbsent(key, k -> new SubSubBean());
}

Isn't that a beauty ;)

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More