minimalcode-org / minimalcode-beans

Minimalistic high-level wrapper functionality for JavaBean
6 stars 0 forks source link

Improvement: forced set of property #4

Open bligny opened 8 years ago

bligny commented 8 years ago

Hello

Your "Beans" library looks really great ! I like it very much :-D

I would like to submit you a request for a possible improvement, regarding the auto-instancing features in the context of indexed properties.

Would it be possible to accept(*) property pattern like;

wrapper.setValue("children[0].firstName", "Bernard");

Instead of:

wrapper.setValue("children[0]", new Child());
wrapper.setValue("children[0].firstName", "Bernard");

My list is generics-oriented:

 class Family{
        private List<Child> children = new ArrayList<>();       
        public List<Child> getChildren() {
            return children;
        }
        public void setChildren(List<Child> children) {
            this.children = children;
        }       
    }

class Child{
        private String firstName;
        public String getFirstName() {
            return firstName;
        }
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }   
    }

This requirement corresponds to the "setPropertyForced" functionnality available in Jodd: http://jodd.org/doc/beanutil.html#forced-setting-of-nested-properties Kind regards,

Bernard. Enterprise Java Architect


(*) Currently stack-trace is:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(ArrayList.java:653)
    at java.util.ArrayList.get(ArrayList.java:429)
    at org.minimalcode.beans.ObjectWrapper.getIndexedValue(ObjectWrapper.java:602)
    at org.minimalcode.beans.ObjectWrapper.getValue(ObjectWrapper.java:549)
    at org.minimalcode.beans.ObjectWrapper.setValue(ObjectWrapper.java:690)
    at org.minimalcode.beans.ObjectWrapper.setValue(ObjectWrapper.java:303)
    at net.haulogy.cms.gateway.test.IndexedTest.wishItCouldWork(IndexedTest.java:41)
dewos commented 8 years ago

Hi @bligny thanks for the compliments. This is related to #2 . And yes, the feature is possible, but it needs a refactor of the business logic and right now I don't have the time to do it.

Probably I'll do it during next summer. I keep this open as a reminder.