Arthur Ronald
Arthur Ronald

Reputation: 33785

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

Upvotes: 0

Views: 1967

Answers (1)

tim_yates
tim_yates

Reputation: 171084

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}]

Upvotes: 3

Related Questions