Muhammad Gelbana
Muhammad Gelbana

Reputation: 4000

Native tapestry5 v5.3.6 map binding

I have a property object called ixlTest which has a map. This map holds another maps which I need to bind the latter's objects in my page's template file. Pretty complex object graph.

I'm basically trying to do this:

ixlTest.parameterGroups{'testOptions'}{'serverIp'}.value

ixlTest is a property object in my page parameterGroups is a member variable in ixlTest. This variable is a map. parameterGroups has an entry with the key testOptions, which has another map with the key serverIp which is an object that has a variable called value that I need to bind within my template file.

I need to use tapestry's native support for that and no other libraries and I also need not to use methods to abstract the operation as I've been through that road and it was pretty inefficient.

Thank you.

Upvotes: 0

Views: 80

Answers (1)

Howard M. Lewis Ship
Howard M. Lewis Ship

Reputation: 2337

There are times when it is just better to put this in Java (or Groovy, or Scala) code on the page and reference that from the template.

Tapestry's property expression syntax doesn't have an operator for de-referencing maps; but you can invoke the get() method ... but there's limits to Tapestry ability to figure out generics, which means you may get errors about missing properties.

I would code this as:

value="testValue"

in the template, and:

public String getTextValue() {
    return ixlTest.getParameterGroups().get("testOptions").get("serverId").getValue(); 
}

in the class.

Since you can change Java code on the fly, this is often better than putting complex expressions into the template; refactoring things on the Java side can break complex expressions inside template, where the IDE is not aware of them.

Upvotes: 1

Related Questions