Monday, March 22, 2010

Nested tables With DisplayTag

I've been using DisplayTag for a long time but never cover its all functions. Today I've to list a collection of ojects with a List property also need to be iterated. DisplayTag's nested table display is what I need.


http://displaytag.homeip.net/displaytag-examples-1.2/img/displaytag.png

The display tag library is an open source suite of custom tags that provide high-level web presentation patterns which will work in an MVC model. The library provides a significant amount of functionality while still being easy to use.

I followed the nested tables example you can find at here. However, this example does not go through after I copy paste. I think there is a mistake in the nesting EL expressions

The difficulty is how to pass the child List property to the nested table, since :
You can't use page attributes created by the parent table for iteration in the nested table (for example if you have a parent table with id="parent" you can't use name="pageScope.parent" as source for the nested table).

the table's data is, let's say "projectList", the nested table's data is "projectList[rowIndex].developers". Since the "rowIndex" is obtained from DisplayTag's implicit objects, nesting EL expressions is used.
//DisplayTag's implicit objects, get the row's number, start from 1.
${projectList_rowNum} 
//In Java, the index begin at 0, so need to minus 1

//use the square brackets notation to get row's projectList
${projectList[rowIndex].developers} 

In their example, they define:

${nestedName} will get a String value, not the List.

The full example as following:


  
  
  

  

  

   
  
  
 
  



2 comments:

Lincoln said...

Have you tried JSF? :)

Laurino said...
This comment has been removed by the author.