If you are not only since Grails with Web applications based on Java, employs the expected JSP Taglib DisplayTag be a term.
DisplayTag it without big pull-up tables in Java Server Pages to split multiple pages (paging), sort of, to group and, csv, xml and pdf export to Excel.
Grails was supported "out of the box" only the paging and long time we do not use JSP Tag Libs in Grails, so that one could map the remaining functions either through plugins or even had to lend a hand.
Since Grails 1.1 This restriction is now lifted and the two unite the test has long been completed successfully. Only the blog entry about it is since the still on my ToDo list. But what will come to those good (I hope
).
The following steps are necessary to integrate DisplayTag in Grails:
libs
First, the libraries are DisplayTag next to the database drivers copied into lib directory.

DisplayTag configuration file
The configuration file of DisplayTag displaytag.properties must be below src/java to be created. The structure of this file is in the document DisplayTag described. For my grum project is the configuration like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| csv excel xml pdf export. csv excel xml pdf types =
true export. excel = true
true export. csv = true
true export. xml = true
true export. pdf = true
= org. displaytag . export . excel . DefaultHssfExportView export. excel. class = org. DisplayTag. export. excel. DefaultHssfExportView
= org. displaytag . export . DefaultPdfExportView export.. pdf class = org. DisplayTag. export. DefaultPdfExportView
= org. displaytag . export . DefaultRtfExportView export. rtf. class = org. DisplayTag. export. DefaultRtfExportView
div class = "exportlinks" > Export to : { 0 } </ div > export. banner = <div class = "export left"> Export to: (0) </ div>
list export. amount = list
= bottom paging. banner. = bottom placement
= No data found. basic. msg. empty_list = No data found.
. empty_list_row =< tr class = "empty" >< td colspan = "0" > No data found. </ td ></ tr ></ tr > basic. msg. empty_list_row = <tr class = "empty"> <td colspan = "0"> No data found. </ td> </ tr> </ tr>
=< span class = "pagelinks" >< a href = "{1}" >< strong >& lt ;& lt ;</ strong ></ a >& nbsp ;& nbsp ;& nbsp ;< a href = "{2}" >< strong >& lt ;</ strong ></ a >& nbsp ; { 0 } & nbsp ;< a href = "{3}" >< strong >& gt ;</ strong ></ a >& nbsp ;& nbsp ;& nbsp ;< a href = "{4}" >< strong >& gt ;& gt ;</ strong ></ a ></ span > paging. banner. full = <span class = "pagelink"> <a href = "(1)"> <strong> & lt; & lt; </ strong> </ a> & nbsp; & nbsp; & nbsp; <a href = "(2)"> <strong> & lt; / strong> </ a> & nbsp; (0) & nbsp; <a href = "(3)"> <strong> & gt <, < / strong> </ a> & nbsp; & nbsp; & nbsp; <a = "(4)"> <strong> & href gt; & gt; </ strong> </ a> </ span>
=< span class = "pagelinks" > { 0 } & nbsp ;< a href = "{3}" >< strong >& gt ;</ strong ></ a >& nbsp ;& nbsp ;& nbsp ;< a href = "{4}" >< strong >& gt ;& gt ;</ strong ></ a ></ span > paging. banner. first = <span class = "pagelink"> (0) & nbsp; <a href = "(3)"> <strong> &; gt </ strong> </ a> & nbsp; & nbsp; & nbsp; <a href = "(4)"> <strong> & gt; & gt; </ strong> </ a> </ span>
=< span class = "pagelinks" >< a href = "{1}" >< strong >& lt ;& lt ;</ strong ></ a >& nbsp ;& nbsp ;& nbsp ;< a href = "{2}" >< strong >& lt ;</ strong ></ a >& nbsp ; { 0 } </ span > paging. banner last. = <span class = "pagelink"> <a href = "(1)"> <strong> & lt; & lt; </ strong> </ a> & nbsp; & nbsp; & nbsp; <a href = "(2)"> <strong> & lt; </ strong> </ a> & nbsp; (0) </ span>
=< span class = "pagebanner" > 1 Record found. Seite : </ span > paging. banner. one_item_found = <span class = "pagebanner"> 1 Record found. Page: </ span>
=< span class = "pagebanner" > { 0 } Records found. Seite : </ span > paging. banner. all_items_found = <span class = "pagebanner"> (0) records found. Page: </ span>
=< span class = "pagebanner" > { 0 } Records found, show { 2 } - { 3 } . </ span >< br />< br /> paging. banner. some_items_found = <span class = "pagebanner"> (0) records found, show (2) - (3). </ span> <br /> <br /> |
DisplayTag Wrapper
Shared Links and formatting are implemented on the Decorator Pattern DisplayTag. The Decorator is a wrapper class implemented in the course in Grails is written in Groovy. My implementation is the class DisplaytagWrapper , the project grum a link to the details of the user created in the format and creation date.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| package de.koo.grum.groovy.util
; import org.displaytag.decorator.TableDecorator;
TableDecorator { public class extends DisplaytagWrapper TableDecorator (
GetLinkToUser String () (
def getCurrentRowObject user = ()
/grum/user/show/${user.id} \" >${user.username}</a>" ; return "<a href= \" /grum/user/show/${user.id} \"> $ (user.username) </ a>";
)
GetUserCreatedAt String () (
def getCurrentRowObject user = ()
. format ( "dd.MM.yyyy HH:mm" ) ; return user createdate.. format ("dd.MM.yyyy HH: mm");
)
) |
Export filter
be set when exporting into an HTML format, the content type for the response to the browser. So that this does not lead to problems, one should filter in the web.xml file can be defined, counteracting the possible errors. DisplayTag brings the class ResponseOverrideFilter already an implementation for it with.
To Grails in changes to the web.xml to make, you need the templates are installed:
Then there is the web.xml in the directory src/templates/war . For the filter, the following entries are necessary.
1
2
3
4
5
6
7
8
| <filter>
<filter-name> ResponseOverrideFilter </ filter-name>
<filter-class> org.displaytag.filter.ResponseOverrideFilter </ filter-class>
</ Filter>
<filter-mapping>
<filter-name> ResponseOverrideFilter </ filter-name>
<url-pattern> / * </ url-pattern>
</ Filter-mapping> |
Involvement in Groovy Server Page
If you have completed all these preparatory steps, you can finally get down to using DisplayTag in a Groovy Server Page.
In my example, user / list.gsp user data are all displayed in a table. The table is by the attribute sortable by name and surname sortable ago (without a new database access) and is reached when the pagesize of the attribute partialList distributed on several pages.
1
2
3
4
5
6
7
8
9
10
11
12
13
| = "display" % > <% @ Taglib uri = "http://displaytag.sf.net" prefix = "display"%>
<html>
..
defaultsort = "1" partialList = "true" <Display: table name = "userList" DefaultSort = "1" partialList = "true"
decorator = "de.koo.grum.groovy.util.DisplaytagWrapper"
= "${pageSize}" requestURI = "/grum/user/list" size = "$ (ResultSize)" pagesize = "$ (pageSize)" requestURI = "/ grum / user / list"
= "0" cellspacing = "0" sort = "list" > class = "listing" cellpadding = "0" cellspacing = "0" sort = "list">
title = "Userame" /> <display:column property = "linkToUser" title = "Userame" />
title = "Firstame" sortable = "true" /> <display:column property = "firstname" title = "Firstame" sortable = "true" />
title = "Lastname" sortable = "true" /> <display:column property = "lastname" title = "Lastname" sortable = "true" />
title = "Created At" sortable = "true" /> <display:column property = "userCreatedAt" title = "Created At" sortable = "true" />
</ Display: table>
... |
With additional attributes ( export , group ) may, as in the example contact data / list.gsp also export to different output formats and a grouping of entries are reached.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| export = "true" defaultsort = "1" partialList = "true" <Display: table name = "contactDataList" export = "true" DefaultSort = "1" partialList = "true"
decorator = "de.koo.grum.groovy.util.DisplaytagWrapper"
= "${pageSize}" requestURI = "/grum/contactData/list" size = "$ (ResultSize)" pagesize = "$ (pageSize)" requestURI = "/ grum / contact data / list"
= "0" cellspacing = "0" sort = "list" > class = "listing" cellpadding = "0" cellspacing = "0" sort = "list">
value = "contactData.csv" /> <display:setProperty name = value = "export.csv.filename" "contactData.csv" />
value = "contactData.xls" /> <display:setProperty name = value = "export.excel.filename" "contactData.xls" />
value = "contactData.xml" /> <display:setProperty name = value = "export.xml.filename" "contactData.xml" />
value = "contactData.pdf" /> <display:setProperty name = value = "export.pdf.filename" "contactData.pdf" />
value = "list" /> <display:setProperty name = value = "export.amount" "list" />
title = "Name" sortable = "true" group = "1" /> <display:column property = "linkContactDataToUser" title = "Name" sortable = "true" group = "1" />
title = "type" sortable = "true" /> <display:column property = "type" title = "type" sortable = "true" />
sortable = "true" /> <display:column property = "data" sortable = "true" />
</ Display: table> |
Conclusion:
Once configured DisplayTag one of the greatest solutions for Java-based Web applications to data list table. The functionality of this far exceeds the standard functionality of Grails. The combination of Grails and DisplayTag I can therefore recommend to anyone.
Links:
grum Source
Similar items: posted by gklinkmann \ \ tags: Grails , groovy , Java , Open Source