I am trying to use loop component as follows.

<tr t:type="Loop" t:source="summarizer.byAssociationConceptSorted" t:value="entry" >
    <td style="border: 1px solid #EEEEEE; padding: 3px">${page.store.loadConcept(${entry.key}).name}</td>
    <td style="border: 1px solid #EEEEEE; padding: 3px">${entry.value}</td>
</tr>

Here, entry.key is String and entry.value is Long

It generates an exception in Tapestry....."Could not convert 'page.store.loadConcept(${entry.key' into a component parameter binding: Error parsing property expression 'page.store.loadConcept(${entry.key': Unable to parse input at character position 25."

It works fine if I do as follows,

<tr t:type="Loop" t:source="summarizer.byAssociationConceptSorted" t:value="entry" >
    <td style="border: 1px solid #EEEEEE; padding: 3px">${entry.key}</td>
    <td style="border: 1px solid #EEEEEE; padding: 3px">${entry.value}</td>
</tr>

This works fine. Exception is thrown when I try to use entry.key within an expression.

I am also able to use the method loadConcept like this,

<tr t:type="Loop" t:source="summarizer.byAssociationConceptSorted" t:value="entry" >
    <td style="border: 1px solid #EEEEEE; padding: 3px">${page.store.loadConcept('some id').name}</td>
    <td style="border: 1px solid #EEEEEE; padding: 3px">${entry.value}</td>
</tr>

This is means that the problem is not with method or entry.key. The problem is when you try use entry.key within an expression. I am new to Tapestry and trying to learn it, can anyone tell me how to use loop value within some expression?

有帮助吗?

解决方案

You can't use expression inside other expression in tapestry. It is always recommended to use separate method in java class for such expressions e.g.:

<tr t:type="Loop" t:source="summarizer.byAssociationConceptSorted" t:value="entry" >
    <td>${entryConcept.name}</td>
    <td>${entry.value}</td>
</tr>

And in java class:

public Concept getEntryConcept() {
    return getPage().getStore().loadConcept(entry.getKey());
}

It is also possible but not recommended to use something like this:

<tr t:type="Loop" t:source="summarizer.byAssociationConceptSorted" t:value="entry" >
    <td>${page.store.loadConcept(entry.key).name}</td>
    <td>${entry.value}</td>
</tr>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top