displaytag
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

displaytag

on

  • 9,836 views

a guide to the display tag

a guide to the display tag

Statistics

Views

Total Views
9,836
Views on SlideShare
9,824
Embed Views
12

Actions

Likes
1
Downloads
126
Comments
0

2 Embeds 12

http://www.slideshare.net 11
http://localhost 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

displaytag Presentation Transcript

  • 1. Gökhan Tanışık [email_address] 17.07.2008 displaytag
  • 2. Session Objectives
    • This session is learning about the displaytag:
      • What displaytag is
      • Why do we use it
      • The properties of the displaytag
  • 3. Agenda
    • What displaytag is?
    • What can I do with it?
    • Basic usage
    • Implicit Object
    • Supported Data
    • Using With Database
    • Using Decorators to Transform Data
    • Generating Links
    • Exporting Table
    • Sorting Data
  • 4. What displaytag is?
    • 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.
  • 5. What can I do with it?
    • Actually the display tag library can just... display tables!
    • Give it a list of objects and it will handle column display, sorting, paging, cropping, grouping, exporting, smart linking and decoration of a table in a customizable XHTML style.
  • 6.  
  • 7. Basic Usage (example_1)
    • <jsp:root version=&quot;1.2&quot; xmlns:jsp=&quot;http://java.sun.com/JSP/Page&quot; xmlns:display=&quot;urn:jsptld:http://displaytag.sf.net&quot;>
    • <jsp:directive.page contentType=&quot;text/html; charset=UTF8&quot; />
    • <jsp:directive.page import=&quot;org.displaytag.sample.*&quot; />
    • <head>
    • <title>displaytag examples</title>
    • <style type=&quot;text/css&quot; media=&quot;all&quot;> @import url(&quot;css/displaytag.css&quot;); </style>
    • </head>
    • <jsp:scriptlet> request.setAttribute( &quot;test&quot;, new TestList(10, false) ); </jsp:scriptlet>
    • <h2>Columns</h2>
    • <display:table name=&quot;test&quot; >
    • <display:column property=&quot;id&quot; title=&quot;ID&quot; />
    • <display:column property=&quot;name&quot; />
    • <display:column property=&quot;email&quot; />
    • <display:column property=&quot;status&quot; />
    • <display:column property=&quot;description&quot; title=&quot;Comments&quot; />
    • </display:table>
    • </jsp:root>
  • 8.  
  • 9. Examining the example_1
    • xmlns:display=“urn:jsptld:http://displaytag.sf.net”,
      • Declares the namespace of the display tag , “xmlns :display… ” => display is the prefix will be used for the display tag.
    • @import url(&quot;css/displaytag.css&quot;)
      • Formats the view of the table
    • request.setAttribute( &quot;test&quot;, new TestList(10, false ) );
      • Declares a random list and fills it with 10 random objects. The object in the list has attributes: “ id, name, email, status, description ”. It is declared in the org.displaytag.sample package
  • 10. Examining the example_1(2)
    • <display:table name=“test”>
      • The decleration of a simple table, gets the properties from the “ test<TestList> ” we declerad before.
    • <display:column property=&quot;id&quot; title=&quot;ID&quot; />
      • A simple column decleration, “property” used for the property to display, in here, it is the “id” attribute of the current object in the “test” list.
      • “ title” is used to define the title of the column. If we don’t use it, property name is used as default.
  • 11. Implicit objects-example_2
    • <jsp:scriptlet> request.setAttribute( &quot;test&quot;, new TestList(10, false) ); </jsp:scriptlet>
    • <h2>Implicit objects created by table</h2>
    • <display:table name=&quot;test&quot; id=&quot;testit&quot; >
    • <display:column property=&quot;id&quot; title=&quot;ID&quot; />
    • <display:column property=&quot;name&quot; />
    • <display:column title=&quot;static value&quot;>static</display:column>
    • <display:column title=&quot;row number (testit_rowNum)&quot;>
    • <c:out value=&quot;${testit_rowNum}&quot;/>
    • </display:column>
    • <display:column title=&quot;((ListObject)testit).getMoney()&quot;>
    • <c:out value=&quot;${testit.money}&quot;/>
    • </display:column>
    • <display:column property=&quot;money&quot;/>
    • </display:table>
  • 12.  
  • 13. Examining the example_2
    • <display:table name=&quot;test&quot; id=&quot;testit&quot; >
      • If you add an “id” attribute to the table tag, then it makes the object corresponding to the given row available in the page context, so you could use it inside scriplet code or some other tag.
      • you can access it using pageContext.getAttribute(&quot;id&quot;) or <% id %> (but only if the value is not a run time expression), the preferred way is the first one.
    • <display:column title=&quot;static value&quot;>static</display:column>
      • You can use a static value for a column
  • 14. Examining the example_2(2)
    • <c:out value=&quot;${testit_rowNum}&quot;/>
      • You can get the row number of the table as: yourTableId_ rowNum
    • <display:column title=&quot;((ListObject)testit).getMoney()&quot;>
    • <c:out value=&quot;${testit.money}&quot;/>
    • </display:column>
      • As we mentioned above we can use the id of the table as a reference to that row. Thus testit.money means the money attribute of the current row
    • <display:column property=&quot;money&quot;/>
      • Has the same meaning with above
  • 15. Supported Data
    • The table tag supports the following kind of objects
      • a Collection
      • an Enumeration
      • a Map (values are displayed in row)
      • a Dictionary (values are displayed in row)
      • an array
      • an Iterator
      • any Object with an iterator() method
      • ... any other object will be displayed on a single row
  • 16. Using With Database
    • Using JSTL
    • <sql:query var=&quot;results&quot;>
    • select * from table
    • </sql:query>
    • <display:table name=&quot;${results.rows}&quot; />
    • (or
    • <display:table name=&quot;pageScope.results.rows&quot; />
    • if not using the EL version)
  • 17. Using With Database(2)
    • Using dynabeans
    • <%
    • Connection con = ...; // just open a connection
    • Statement stmt = con.createStatement();
    • ResultSet rs = stmt.executeQuery(&quot;SELECT * from table&quot;);
    • RowSetDynaClass resultSet = new RowSetDynaClass(rs, false);
    • stmt.close();
    • con.close();
    • request.setAttribute(&quot;results&quot;, resultSet);
    • %>
    • <display:table name=&quot;requestScope.results.rows&quot; />
  • 18. Using Decorators to Transform Data
    • <h2>Using decorators to transform data</h2>
    • <display:table name=&quot;test&quot; decorator=&quot;org.displaytag.sample.decorators.Wrapper&quot;>
    • <display:column property=&quot;id&quot; title=&quot;ID&quot; />
    • <display:column property=&quot;email&quot; />
    • <display:column property=&quot;status&quot; />
    • <display:column property=&quot;date&quot; />
    • <display:column property=&quot;money&quot; />
    • </display:table>
  • 19. Output with decoration
  • 20. Output with decoration
  • 21. Using Decorators to Transform Data(2)
    • You can specify decorators that work on individual columns.
    • Example:
    • <display:table name=&quot;test&quot;>
    • <display:column property=&quot;date&quot; decorator=&quot;org.displaytag.sample.LongDateWrapper&quot; />
    • </display:table>
  • 22. Generating Links
    • autolink
    • If you have a link in the column you can use it (true/false)
    • or
    • href
      • the base URL used to construct the dynamic link
    • paramId
      • the name of the parameter that gets added to the URL specified above
    • paramName
      • name of the bean that contains the data we want to tack on the the URL (typically null, indicating the current object in the List)
    • paramProperty
      • property to call on the object specified above to return the value that gets tacked onto the URL.
    • paramScope
      • specific scope where the databean lives, typically null
  • 23. Smart Linking Example
    • <h2>Smart linking of column data</h2>
    • <display:table name=&quot;test&quot;>
    • <display:column property=&quot;id&quot; autolink =&quot;true&quot; title=&quot;ID&quot; />
    • <display:column property=&quot;email&quot; autolink =&quot;true&quot; />
    • <display:column property=&quot;url&quot; autolink =&quot;true&quot; />
    • </display:table>
  • 24.  
  • 25. Dynamic Links-example_3
    • <jsp:scriptlet> Object foo = session.getAttribute( &quot;details&quot; );
    • if( foo == null ) {
    • session.setAttribute( &quot;details&quot;, new TestList(10, false) );
    • }
    • request.setAttribute(&quot;testparam&quot;, &quot;sendamail&quot;);
    • </jsp:scriptlet>
    • <display:table name=&quot;sessionScope.details&quot;>
    • <display:column property=&quot;id&quot; title=&quot;ID&quot; href =&quot;details.jsp“ paramId =&quot;id&quot; />
    • <display:column property=&quot;email&quot; href =&quot;details.jsp&quot; paramId =&quot;action&quot; paramName =&quot;testparam&quot; paramScope =&quot;request&quot; />
    • <display:column property=&quot;status&quot; href =&quot;details.jsp&quot; paramId =&quot;id&quot; paramProperty =&quot;id&quot; />
    • </display:table>
  • 26.  
  • 27. Exporting Table
    • <h2>Data exporting</h2>
    • <display:table name=&quot;test&quot; export=&quot;true&quot; id=&quot;currentRowObject&quot;>
    • <display:setProperty name=&quot;export.rtf.filename&quot; value=&quot;example.rtf&quot;/>
    • <display:column property=&quot;id&quot; title=&quot;ID&quot; />
    • <display:column property=&quot;email&quot; />
    • <display:column property=&quot;status&quot; />
    • <display:column property=&quot;date&quot; />
    • </display:table>
  • 28.
  • 29. Sorting Data
    • <jsp:scriptlet> Object foo = session.getAttribute( &quot;stest&quot; );
    • if( foo == null ) {
    • session.setAttribute( &quot;stest&quot;, new TestList( 10, false ) );
    • } </jsp:scriptlet>
    • <h2>Auto-sorting by columns</h2>
    • <display:table name=&quot;sessionScope.stest&quot; defaultsort=&quot;1&quot; defaultorder=&quot;descending&quot; >
    • <display:column property=&quot;id&quot; title=&quot;ID&quot; sortable=&quot;true&quot; headerClass=&quot;sortable&quot; />
    • <display:column property=&quot;name&quot;
    • <display:column property=&quot;email&quot; />
    • <display:column property=&quot;status” />
    • </display:table>
  • 30.
  • 31. Remainder
    • The presentations is prepared from the tutorial of the display tag in the official site:
    • http://displaytag.sourceforge.net/
    • All the examples and the codes are taken from the site.
    • To find the original examples download the library from the site and import the project displaytag-examples- version .war file to the eclipse or whatever you use...
  • 32. Using displaytag in a project
    • Download the library from
      • http://sourceforge.net/project/showfiles.php?group_id=73068
    • Drop the displaytag-version.jar file in your application WEB-INF/lib directory
    • Make sure the directory includes also
      • commons-logging
      • commons-lang
      • commons-collections
      • commons-beanutils
      • log4j
      • itext (optional, for pdf/rtf export)
  • 33. Thanks…