Search code examples
grailsgroovygsp

Unclosed GSP expression: Grails GSP engine does not resolve nested GSP expression


I need to create a custom gsp whose domain model is designed as follows

class Question {

    SortedSet<Choice> choiceCollection;

    static hasMany = [choiceCollection:Choice]
    static mappping = {
        choiceCollection(joinTable:false)
    }

}

Each Question object has five Choices. So, i create the following snippet of code

create.gsp

<g:each var="i" in="${(1..5)}">
    <div class="fieldcontain  required">
    <label for="description">
            Option ${i}.
            <span class="required-indicator">*</span>
        </label>
        <g:textArea name="choiceCollection[${i}].description" cols="40" rows="5" maxlength="2000" value="${questionInstance?.choiceCollection[${i}]?.description}"/>
    </div>
</g:each>

Although Grails GSP engine complains Unclosed GSP expression which is not true - g:textArea is closed as you can see above -, i believe the real problem is the expression

${questionInstance?.choiceCollection[${i}]?.description}

which involves nested GSP expressions.

Question: am i missing some feature ? If so, what should i do to overcome my obstacle ?

Grails version: 2.1.1


Solution

  • Shouldn't

    ${questionInstance?.choiceCollection[${i}]?.description}
    

    be

    ${questionInstance?.choiceCollection[ i ]?.description}
    

    The set bit:

    Try something like:

    <g:each var="choice" status="i" in="${questionInstance?.choiceCollection}">
    

    So i still contains your index, but choice contains what you were trying to get with questionInstance?.choiceCollection[${i}]