Question

i want to print a matrix with ftl code, so i have two lists activities and skills an activities containt a list of competence so if activities(i) containt the skills(i) i set x in the right position in matrix this my code

 <div id="menu" class="one whole">
<div class="one sixth">a\c</div>
[#list 1..y as i]
<div class="one sixth">c${i}</div>
[/#list]

[#list 1..x as ss]
<div class="one sixth">a${ss}</div>
   [#assign l = activities[ss].getCompetences()?size]
   [#if l > 0]
   [#assign liste = activities[ss].getCompetences()]
   <li><a href="?3.0.1.0">${activities[16].getCompetences()[1].name}</a></li>
   <li><a href="?3.0.1.0">${activities[16].getCompetences()[0].name}</a></li>
 <li><a href="?3.0.1.0">${activities[17].getCompetences()[1].name}</a></li>
 <li><a href="?3.0.1.0">${activities[17].getCompetences()[0].name}</a></li>

            [#list 1..y as j]
            [#assign vrai = 0]
            [#assign x2 = '${skills[j].name}']
            [#assign l = activities[ss].getCompetences()?size]
                [#list 0..l as element]

                [#assign x1 = '${activities[ss].getCompetences()  [element].name}']

                     [#if x1 == x2]
                     [#assign vrai = vrai+1]
                     [/#if]
                [/#list]
                [#if vrai > 0]      
                     <div class="one sixth">X</div>
                [#else]
                     <div class="one sixth">000</div>  
                [/#if]
             [/#list]
    [#else]
       [#list 1..y as j]
       <div class="one sixth">000</div>
       [/#list]     
     [/#if]    
   [/#list]
   </div>

the error is Caused by: freemarker.core.InvalidReferenceException: Expression activities[ss].getCompetences()[element] is undefined on line 25,([#assign x1 = '${activities[ss].getCompetences()[element].name}'])

but this expression is correct here (a) :

  • ${activities[16].getCompetences()[1].name}
  • (b) :
  • ${activities[16].getCompetences()[0].name}
  • i used (a) and (b) just for testing.

    can someone find what is the problem.

            model.put("activities", activities);
        model.put("skills", skills);
        model.put("x", x);
        model.put("y", y);
    
    Was it helpful?

    Solution

    Per the message, a[ss] is undefined. So one possibility is that you have not set a in the freemarker model. Another possibility is that your a list is zero based, not one based. You are iterating 1..x.

    Other than that, you have not provided enough info. Consider providing the full output of the freemarker exception, and more clearly explain what it is that 'a' and x contain.

    OTHER TIPS

    Be careful with the .. operator. Its right hand operand is interpreted as inclusive, so with 0..length you code will fail. And if you try to write 0..(length-1), that will also fail if the length is 0, as it will be [-1, 0] then.

    Also, if you list indexes only to do someList[theIndex] later, you are doing something wrong. You should then list the list items instead, and then if you need the index, use itemName_index (see http://freemarker.org/docs/ref_directive_list.html#ref.directive.list).

    "Expression activities[ss].getCompetences()[element]" means that your index is out of range, or that there's a null in the list at the given index.

    Licensed under: CC-BY-SA with attribution
    Not affiliated with StackOverflow
    scroll top