Reputation: 3058
I understand that the same question already been here. But unfortunately it not helps me to solve my problem. I have HashSet in my FreeMarker template. I would like to show size of the HashSet on the view. I have the following for this:
<td>${repo.getRepoWords().size()}</td>
Method getRepoWords is:
public HashSet getRepoWords() {
return repoWords;
}
As the result I see this exception
FreeMarker template error (DEBUG mode; use RETHROW in production!): For "." left-hand operand: Expected a hash, but this has evaluated to a sequence (wrapper: f.t.SimpleSequence): ==> repo.getRepoWords() [in template "repositories/detail.ftl" at line 24, column 23] ---- FTL stack trace ("~" means nesting-related): - Failed at: ${repo.getRepoWords().size()} [in template "repositories/detail.ftl" at line 24, column 21] ~ Reached through: #nested [in template "layouts/common.ftl" in macro "page" at line 20, column 1] ~ Reached through: @c.page title="Главная страница" [in template "repositories/detail.ftl" at line 2, column 1] ---- Java stack trace (for programmers): ---- freemarker.core.NonHashException: [... Exception message was already printed; see it above ...] at freemarker.core.Dot._eval(Dot.java:48) at freemarker.core.Expression.eval(Expression.java:83) at freemarker.core.MethodCall._eval(MethodCall.java:58) at freemarker.core.Expression.eval(Expression.java:83) at
Can I use the size() method for a HashSet in a FreeMarker template?
Upvotes: 3
Views: 10196
Reputation: 4509
I would suggest you to do use ?size
like below.Please check the Document
${repo.repoWords?size}
Upvotes: 6