Results 1 to 6 of 6

Thread: Dynamic listing binding with binding property

  1. #1

    Default Dynamic listing binding with binding property

    Hi all,

    I'm wondering if anyone has a workaround or proven solution to the following problem.

    I am using Spring Webflow 2.0.9 and need to perform dynamic list binding.

    From the research I have initially carried out it seems that more people have raised JIRA bugs for this rather than aimed to solve it.

    However I think we can be this problem.

    Current I have a sample model class like so:

    Code:
    public class MyModelClass {
        private List<ComplexObject> complexObjects = null;
    
        // Gets and Sets etc etc
    }
    
    public class ComplexObject {
        private String nameOfObject = null;
        private String description = null;
    
        // Gets and Sets etc etc
    }
    Then within Web flow this can be reference like so:

    Code:
    <var name="myModel" class="my.package.MyModelClass" />
    Then my view-state is defined like so:

    Code:
    <view-state id="someId" view="myTemplateView" model="myModel">
        <binder>
                <binding property="complexObjects[0].nameOfObject" />
                <binding property="complexObjects[0].description" />
        </binder>
    </view>
    And finally the JSP code for the fields:

    Code:
    <c:forEach items="${someCollection}" varStatus="loop">
        <form:input path="complexObjects[${loop.index}].nameOfObject" />
        <form:input path="complexObjects[${loop.index}].description" />
    </c:forEach>
    Notice I refer to complexObject[0] as the reference to my binding. However the user can specify any number of complexObjects. So I either add hundreds (I'm exaggerating of course) binding properties to cover all the user may wish to do....or come up with a better solution.

    So far I have tried changing my list of complexObjects to an AutoPopulatingList like so:

    Code:
    public class MyModelClass {
        private AutoPopulatingList<ComplexObject> complexObjects = null;
    
        public MyModelClass() {
            this.complexObjects = new AutoPopulatingList<ComplexObject>(ComplexObject.class);
        }
    
        // Gets and Sets etc etc
    }
    And then change the binding property like so:

    Code:
    <binding property="complexObjects" />
    This works for displaying the form however when the form is submitted the fields are not submitted along with the form.

    Does anyone know any proven work arounds for this?

  2. #2
    Join Date
    Oct 2010
    Posts
    13

    Default

    SWF needs all objects to be serializable if you want to use them in the flow.

    Try to implemet Serializable interface.

  3. #3

    Default Serializable

    Hi there,

    Thank you for the reply and taking the time to read the post. All my objects are Serializable I was aware of this but had forgot to include it on the sample code above.

  4. #4
    Join Date
    Apr 2010
    Location
    New Jersey, NJ
    Posts
    42

    Default

    SWF is not supporting dynamic binding !
    Submit won't fail in 2.0.9 and its bind only initialized array size and ignores the new items.
    In 2.1.x, it fails while binding, it thro some EL parsing exception !

  5. #5

    Default Initial array size

    Hi there,

    Thanks for the reply.

    If it binds only the initial array size - for my requirements that might just be sufficient! I don't add extra form fields via Javascript or anything like that

    I shall give it a test.

  6. #6

    Default JIRA Ticket

    Hi all,

    I have solved my issue because I knew the size of the collection before the state was entered.

    However for those looking at Dynamic list sizes such as adding fields with Javascript, I have found a bug report on the Spring Webflow JIRA

    https://jira.springframework.org/browse/SWF-1065

    The reporter has included a patch which may help people.

    Eggsy

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •