Announcement Announcement Module
Collapse
No announcement yet.
collection binding problem using select tags in freemarker Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • collection binding problem using select tags in freemarker

    I'm having a strange problem binding items of a collection. Here is how I'm set up.

    My backing object et. al.

    Code:
    public class Exam {
    
          java.util.ArrayList testDetailList;  //list of TestDetail
    
    }
    
    public class TestDetail {
    
          TestResult rightTestResult;
          TestResult leftTestResult;
    
    }
    
    public class TestResult {
    
          int       codeId;
          String resultDesc;
    
    }
    The above classes have the necessary getters/setters. Also, I have an appropriate property editor for the above TestResult class to translate from codeId to object and vice-versa.

    I'm using freemarker and so this is how my .ftl file looks where exam is the form backing object of class Exam and testResultsMap is a map of TestResults returned as part of referenceData.

    Code:
    <#list exam.testDetailList as detail>
    
        <@spring.formSingleSelect "exam.testDetailList&#91;$&#123;detail_index&#125;&#93;.rightTestResult",  testResultsMap/> 
    
        <@spring.formSingleSelect "exam.testDetailSet&#91;$&#123;detail_index&#125;&#93;.leftTestResult",  testResultsMap/> 
    
    </#list>
    The above code uses the 'formSingleSelect' .ftl macro copied here for convenience
    Code:
    <#macro formSingleSelect path options attributes="">
    	<@bind path/>
    	<select name="$&#123;spring.status.expression&#125;" $&#123;attributes&#125;>
    		<#list options?keys as value>
    		<option value="$&#123;value&#125;" 
    		<#if spring.status.value?default&#40;""&#41; == value>selected="true"</#if>>$&#123;options&#91;value&#93;&#125;</option>
    		</#list>
    	</select>
    </#macro>
    Upon submit, the above code seems to "do" everthing right, the values for the testDetailList are bound correctly and everything seems fine. However, when I enclose one (or both) of the spring.formSingleSelect tags within another tag like

    Code:
    <#list exam.testDetailList as detail>
    
        <center>
            <@spring.formSingleSelect "exam.testDetailList&#91;$&#123;detail_index&#125;&#93;.rightTestResult",  testResultsMap/> 
        </center>
    
        <@spring.formSingleSelect "exam.testDetailSet&#91;$&#123;detail_index&#125;&#93;.leftTestResult",  testResultsMap/> 
    
    </#list>
    Then, after submission, it is as if the bind on the right side (rightTestResult) is not happening. The same thing occurs regardless of which enclosing tag is used around the spring.formSingleSelect (like <b></b>, <div></div>, <td></td>, etc.)

    I'm new at all of this and I cannot understand what is happening. Does anyone have a clue as to what might be happening here?

    Any help at all is appreciated.

  • #2
    I found the error, and the error was on my part. I somehow had nested an HTML form within another form in my .ftl file, and through all the debugging, just did not see it. Stupid error on my part.

    Comment

    Working...
    X