Mar 22

I have few hours to use up my Google Code hosted project- grum on the state of things done (it was indeed about time). Grum is a little Grails application for user management, which allows me to it with the web framework Grails 'to "play.

I'm aware of in implementing the many Grails Plugins waived in order to have as few side effects as possible and keep it even for those simply looking for an introduction to Grails. Thus, included in Grum solutions, such as one:

  • access to a Mysql database implemented
  • 1:1, 1: n and n: m GORM model relations
  • own days writes Libs
  • the JSP Tag Lib DisplayTag used to display the data page by page, to group, sort, and in all possible formats (excel, csv, xml, pdf) to export
  • allows the upload of files
  • functional tests with the webtest plugin used
  • and the delivery of XML based on specific URL's (short content negotiation) to implement

The new version 0.3 now uses the plugin webtest grails 1.2.1 and in version 2.0.3. The sources , the SQL files to create the Mysql database and a web archive with all required libraries are available on Google Code to download ready.

Nutztungshinweise:
The code can be freely used, but may contain errors, for which I assume no liability. The license of the libraries it should be observed.

Similar items:

posted by gklinkmann \ \ tags: , , , ,

Mar 05

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:

  grails install-templates 

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: , , ,

January 2008

Quietly, she is dahergekommen. Like many other projects Groovy (Groovy 1.7, 0.9 GPars, Gant 1.9) also appeared in time for the Groovy & Grails Grails Exchange, a new version. The final version 1.2 has been a long time coming.

A stable version, it should be. That was the reason for the long beta and RC phase. Sun based Groovy 1.2, nor on the Groovy version 1.6.7.

For the new version has Dierk König (Author of Groovy in Action), a detailed article written so that here only a short list of new features follows:

  • Declarative dependencies for libraries within Grails applications
  • Faster views - performance enhancements for Groovy Server Pages (GSP)
  • GORM defaults are configurable
  • Named queries, which can also serve as a selection basis for the dynamic finder methods
  • Expansion, which eh very good support for REST and JSON
  • the Grails documentation for other engine can not be (used to Grails based) applications
  • Update on Spring 3
  • finely granular configurable Data Sources
  • enhanced support for annotated entities
  • Tomcat as the default servlet container. Other servlet container such as Jetty is also supported.

The complete list of changes you can in the change log and release notes read.

Grails 1.2 is on the project page to download ready. Grails is sufficient for existing applications such as always

  grails upgrade 

The jump from version 1.1 to 1.2 is not as great as that of version 1.0 to 1.1. By thus far are only a few problems known.

Similar items:

posted by gklinkmann \ \ tags: , , ,

Dec 27

canoo webtest Report

The on Groovy -based web framework Grails in the Java world allows rapid development of web applications. The speed you paid for but not by sacrificing the tests. On the contrary.

The Canoo - Web Test Plugin Tests are written as soon as the application itself (which in my view the only way the developer to test to make tasty).

To install a simple enough:

  > Grails install-plugin webtest 

And with:

  1
 2
 3
 4
 5
 6
 7
  > Grails create-webtest
 WebTest name not specified.  Please enter:
 <Domain-name>
      Copying 1 file to < pfad zur Grails App > [Copy] Copying 1 file to <path to Grails App>
      Copying 1 file to </ pfad >< pfad zur Grails App >/ webtest / tests [Copy] Copying 1 file to </ path> <path to Grails App> / webtest / tests
 domain -name > Test.groovy Web Test generated at webtest / tests / <domain-name> Test.groovy
 pfad ></ domain > </ Domain> </ path> </ domain> 

we created his first test for a class of Grails domain. All tests are by default under /webtest/tests stored. A generated test might look like this:
Continue reading »

Similar items:

posted by gklinkmann \ \ tags: , , , ,

Nov 29

grailspodcast logo

One of the most important resources when dealing with Groovy and Grails is, in my view, the Grails podcast by Sven and Haiges and Glen Smith.

The podcast that two weeks in the English language is all, now has the consequence of 100 reached.
All the best from my side to this event and many thanks for the many information and news of recent years on the topics of Groovy and Grails.

Keep on.

Similar items:

posted by gklinkmann \ \ tags: , , , ,