### Displaying Database Results with Dynabeans
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_sources.md
This example demonstrates retrieving data from a database using JDBC, converting it into a RowSetDynaClass, and then displaying it with displaytag.
```html
<%
Connection con = ...; // just open a connection
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * from table");
RowSetDynaClass resultSet = new RowSetDynaClass(rs, false);
stmt.close();
con.close();
request.setAttribute("results", resultSet);
%>
```
--------------------------------
### Configure Displaytag Resource Bundle
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
Set default messages for displaytag resources using the displaytag.properties file. This example sets the message for when only one item is found.
```properties
paging.banner.one_item_found=One item found
```
--------------------------------
### Displaying Database Results with JSTL
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_sources.md
This example shows how to query a database using JSTL's sql:query tag and then pass the results to the displaytag for rendering.
```html
select * from table
```
--------------------------------
### Calculating Starting Record for Paging
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_externalSortAndPage.md
Calculate the starting record index for a given page when using partial lists and external paging. This requires the current page number and the defined pagesize.
```java
(Integer.parseInt(request.getParameter((new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_PAGE)))) - 1) * pageSize.
```
--------------------------------
### Generate Dynamic Links using Decorator - Link 1
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_links.md
Implement a decorator method to dynamically generate HTML links. This example creates a link using the object's ID and the current row index, suitable for drill-down functionality.
```java
public String getLink1()
{
ListObject lObject= (ListObject)getCurrentRowObject();
int lIndex= getListIndex();
return "\";
}
```
--------------------------------
### Translate Displaytag Resources for a Specific Language
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
Add language-specific properties files (e.g., displaytag_it.properties) to translate messages for different locales. This example provides an Italian translation for the 'one item found' message.
```properties
paging.banner.one_item_found=Un solo elemento trovato
```
--------------------------------
### Set Column Header Title Using Property Attribute and Resource Bundle
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
When 'title' and 'titleKey' are omitted, the 'property' attribute is used to look up the column header text in a resource bundle. If not found, the capitalized property value is used. This example assumes JSTL for resource lookup.
```jsp
```
--------------------------------
### Configure Portlet Request Helper
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/portlet.md
Specify the `factory.requestHelper` property in `displaytag.properties` to enable portlet support. Ensure `displaytag-portlet.jar` is in the classpath.
```properties
factory.requestHelper=org.displaytag.portlet.PortletRequestHelperFactory
```
--------------------------------
### Commit Changes to Repository
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/source-repository.md
Execute this command to commit your changes. SVN will prompt for your password.
```bash
$ svn commit --username your-username -m "A message"
```
--------------------------------
### Single Decorator for All Media
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_decorators.md
Use this when a single decorator should handle both HTML rendering and exports to other media. The decorator should be media-agnostic.
```html
```
--------------------------------
### Checkout Source Code Behind Firewall
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/source-repository.md
For users behind a corporate firewall blocking HTTP access, try accessing the repository via the developer connection.
```bash
$ svn checkout https://svn.code.sf.net/p/displaytag/code/trunk displaytag
```
--------------------------------
### Configure Export Types
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/export.md
Add custom export media types to the list of available export options in displaytag.properties.
```properties
export.types=csv excel xml [mymedia]
```
--------------------------------
### Method Parameter Naming
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/coding_conventions.md
Method parameters should not have any prefix.
```Java
public void someMethod(String className)
{
}
```
--------------------------------
### Add SLF4J Logging Implementation
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/dependencies.md
To use SLF4J for logging with displaytag, include a logging implementation. The log4j adapter is a common choice.
```xml
org.slf4j
slf4j-log4j12
1.7.7
```
--------------------------------
### Checkout Source Code with Developer Access
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/source-repository.md
Developers can check out the Subversion repository via HTTPS. Committers must use this method.
```bash
$ svn checkout svn+ssh://fgiust@svn.code.sf.net/p/displaytag/code/trunk displaytag
```
--------------------------------
### Different Decorators per Media Type
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_decorators.md
Configure distinct decorators for HTML, PDF, RTF, and Excel exports using setProperty tags. This allows for media-specific formatting and functionality.
```html
```
--------------------------------
### Configure Subversion Proxy Settings
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/source-repository.md
Edit the 'servers' configuration file to specify proxy details for Subversion client access.
```ini
[global]
http-proxy-host = your.proxy.name
http-proxy-port = 3128
```
--------------------------------
### Checkout Source Code Anonymously
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/source-repository.md
Use this command to check out the source code anonymously from the SVN repository.
```bash
$ svn checkout https://svn.code.sf.net/p/displaytag/code/trunk/ displaytag
```
--------------------------------
### Equivalent Java Method Calls for Nested Properties
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_sources.md
This shows the equivalent Java method calls for the non-EL syntax used to access nested properties, illustrating the underlying mechanism.
```html
session.getAttribute("list").getValue().getAttribute("name").getItem(1)
```
--------------------------------
### Keyword Spacing and Binary Operator Spacing
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/coding_conventions.md
Keywords followed by parentheses should be separated by a space. Binary operators must be separated from their operands by spaces.
```Java
while (true) {
// some code
}
```
```Java
a += c + d;
a = (a + b) / (c * d);
```
```Java
while (d++ = s++) {
n++;
}
```
```Java
printSize("size is " + foo + "\n");
```
--------------------------------
### Basic Table Rendering
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_basic.md
Use this snippet to render a table directly from a List attribute in the request. The tag automatically generates columns based on object properties.
```html
<% request.setAttribute( "test", new TestList(10, false) ); %>
```
--------------------------------
### Configure Struts Locale Adapter
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
Specify the Struts locale adapter in displaytag.properties to resolve the locale based on Struts' Globals.LOCALE_KEY.
```properties
locale.resolver=org.displaytag.localization.I18nStrutsAdapter
```
--------------------------------
### Configure Custom Export View
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/export.md
Define properties for a custom export view, including its class, label, and whether to include the header. The filename property can be set to force download.
```properties
export.[mymedia]=true
export.[mymedia].class=fully.qualified.class.name
export.[mymedia].label=Click here to try my export
# include header parameter is forwarded to your export view
export.[mymedia].include_header=true
# if set, file is downloaded instead of opened in the browser window
export.[mymedia].filename=
```
--------------------------------
### Configure Custom Locale Resolver
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
Configure a custom locale resolver by specifying its fully qualified class name in displaytag.properties. The custom implementation must implement the org.displaytag.localization.LocaleResolver interface.
```properties
locale.resolver=com.example.MyLocaleResolver
```
--------------------------------
### External Sorting and Paging with Partial Lists
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_externalSortAndPage.md
Enable external sorting and paging for partial lists by setting 'partialList="true"' and providing the total list size via the 'size' attribute. A 'pagesize' must also be specified.
```jsp
```
--------------------------------
### Generate Dynamic Links using Decorator - Link 2
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_links.md
A decorator method to create multiple dynamic links for actions like 'view', 'edit', and 'delete' based on the object's ID. This provides a set of actions for each row.
```java
public String getLink2()
{
ListObject lObject= (ListObject)getCurrentRowObject();
int lId= lObject.getId();
return "\View\ | "
+ "\Edit\ | "
+ "\Delete\";
}
```
--------------------------------
### Configure Webwork Locale Adapter
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
Specify the Webwork2 locale adapter in displaytag.properties to resolve the locale using the first LocaleProvider action in the stack.
```properties
locale.resolver=org.displaytag.localization.I18nWebworkAdapter
```
--------------------------------
### Configure JSTL Locale Adapter
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
Specify the JSTL locale adapter in displaytag.properties to mimic JSTL's locale resolution, looking for a locale in the session with the Config.FMT_LOCALE key.
```properties
locale.resolver=org.displaytag.localization.I18nJstlAdapter
```
--------------------------------
### Add Apache POI Dependency for Excel Export
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/dependencies.md
If you need to export data to Excel using the binary format, include the Apache POI dependency. This is required for the poi exporter.
```xml
org.apache.poi
poi
3.10-FINAL
```
--------------------------------
### Column Content Definition
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_basic.md
Illustrates two ways to define column content: using the 'property' attribute to map to an object's getter method, or providing static content directly within the column tag body.
```html
email@it.com
```
--------------------------------
### Add Displaytag Dependency
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/dependencies.md
Include this dependency in your Maven POM file to add displaytag to your project. Maven will manage all required libraries.
```xml
org.displaytag
displaytag
2.0
```
--------------------------------
### Maven Dependency for Displaytag Excel Export
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/install.md
Add the displaytag-export-poi module as a dependency if you need optional Excel export functionality. This requires the POI library.
```xml
org.displaytag
displaytag-export-poi
1.1.1
```
--------------------------------
### Display Columns with Dynamically Generated Links
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_links.md
Configure the display:table to use a decorator and display columns that contain dynamically generated HTML links. This allows for custom link text and actions based on row data.
```html
```
--------------------------------
### JSP XML Syntax Declaration
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/install.md
If using JSP XML syntax, declare the displaytag tag library with the jsp:root element. Ensure the namespace URI matches the TLD.
```html
```
--------------------------------
### Table with Defined Columns
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_basic.md
Define specific columns for your table by mapping properties of the list objects to column headers. This provides more control over table structure and content.
```html
<% request.setAttribute( "test", new TestList(10, false) ); %>
```
--------------------------------
### Qualified Imports
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/coding_conventions.md
All import statements must contain the full class name and should not use the wildcard notation ('*').
```Java
// Correct
import java.util.Date;
import java.net.HttpURLConnection;
// Not correct
import java.util.*;
import java.net.*;
```
--------------------------------
### Configure Spring Locale Adapter
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
Specify the Spring locale adapter in displaytag.properties to resolve the locale using Spring's RequestContextUtils.getLocale(), which delegates to the Spring locale resolver.
```properties
locale.resolver=org.displaytag.localization.I18nSpringAdapter
```
--------------------------------
### Displaytag Table with Column Decorator
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_decorators.md
Apply a specific decorator to an individual column for data formatting. This is useful for reusable formatters like date formatting.
```html
```
--------------------------------
### Configure ResponseOverrideFilter in web.xml
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/export_filter.md
This XML snippet shows how to declare the ResponseOverrideFilter in your web.xml file. This filter is essential for handling displaytag exports correctly.
```xml
ResponseOverrideFilter
org.displaytag.filter.ResponseOverrideFilter
```
--------------------------------
### Displaytag Table with Custom Decorator
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_decorators.md
Use a table decorator to format various properties of business objects displayed in a table. The decorator class must subclass TableDecorator.
```html
```
--------------------------------
### Setting a List Bean in Request Scope
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_sources.md
This scriptlet sets a list of data to be displayed by the displaytag. It is typically used in a JSP page or an Action class.
```html
<% request.setAttribute( "test", new TestList( 10 ) ); %>
```
--------------------------------
### Map ResponseOverrideFilter URLs in web.xml
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/export_filter.md
These XML snippets demonstrate how to map the ResponseOverrideFilter to specific URL patterns in your web.xml. This ensures the filter intercepts requests for the specified file types.
```xml
ResponseOverrideFilter
*.do
```
```xml
ResponseOverrideFilter
*.jsp
```
--------------------------------
### Decorator Attribute Precedence Over Media Properties
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_decorators.md
When both the 'decorator' attribute and 'decorator.media.*' properties are set, the 'decorator' attribute takes precedence. Media-specific properties are ignored in this case.
```html
```
--------------------------------
### Set Column Header Title Using Resource Bundle Key
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
Use the 'titleKey' attribute to look up the column header text from a resource bundle. If the key is not found, '???key???' will be displayed.
```jsp
```
--------------------------------
### Class Variable Declaration and Usage
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/coding_conventions.md
Class variables should not have any prefix and must be referenced using the 'this' object.
```Java
public class SomeClass
{
private String someString;
...
public void someMethod() {
logger.debug("Value = " + this.someString);
}
}
```
--------------------------------
### Configure Displaytag CSS Class
Source: https://github.com/hazendaz/displaytag/blob/master/README.md
Set the `css.table` property to an empty string in `displaytag.properties` to prevent displaytag from adding the 'table' class to tables. This is necessary for compatibility with older versions of AjaxTags.
```properties
css.table=
```
--------------------------------
### Determining Sort Order Parameter Name
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_externalSortAndPage.md
Use ParamEncoder to dynamically determine the request parameter name for sort order (ASC/DESC).
```java
new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_ORDER))
```
--------------------------------
### External Sorting Configuration
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_externalSortAndPage.md
Configure DisplayTag to use external sorting by setting 'sort="external"' on the table tag. Columns can be made sortable using 'sortable="true"' and specifying a 'sortName'.
```jsp
```
--------------------------------
### Displaytag Table with Implicit Objects
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_implicitobjects.md
This snippet demonstrates how to use implicit objects like the row object and row number within scriptlets when an 'id' attribute is set on the display:table tag.
```html
static
<%=pageContext.getAttribute("testit_rowNum")%>
<%=((ListObject)pageContext.getAttribute("testit")).getMoney()%>
```
--------------------------------
### Determining Sort Parameter Name
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_externalSortAndPage.md
Use ParamEncoder to dynamically determine the request parameter name for column sorting.
```java
new ParamEncoder(tableId).encodeParameterName(TableTagParameters.PARAMETER_SORT))
```
--------------------------------
### Enable Autolinking for Email and URLs
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_links.md
Set the autolink attribute to true on a display:column tag to automatically convert email addresses and URLs within the column data into hyperlinks. This is useful for displaying contact information or web links directly.
```html
```
--------------------------------
### Dynamic SVG Sprite CSS Loader
Source: https://github.com/hazendaz/displaytag/blob/master/displaytag-examples/src/main/webapp/docroot/img/sprite/svg-loader-fragment.html
This script detects SVG support and loads the correct CSS file for SVG sprites. It's designed to be included in HTML to ensure proper rendering of SVG assets.
```javascript
!function(){var e=window,t=e.document,s=arguments,a="createElementNS",n="http://www.w3.org/",A="svg",r=function(e){var r=t.getElementsByTagName("script")[0],g=t.createElement("link");g.rel="stylesheet",g.type="text/css",g.href=s[4]+s[1*e|2*(t[a]&&t[a](n+"2000/"+A,A).createSVGRect&&t.implementation.hasFeature(n+"TR/SVG11/feature#Image","1.1"))],r.parentNode.insertBefore(g,r)},g=new e.Image;g.onerror=function(){r(0)},g.onload=function(){r(1===g.width&&1===g.height)},g.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="}("svg-png-sprite.css","svg-png-data.css","svg-svg-sprite.css","svg-svg-data.css","/img/sprite/");
```
--------------------------------
### Mandatory Brackets on New Lines
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/coding_conventions.md
All brackets for classes, methods, and control structures must begin and end on a new line. This applies even to single-line statements.
```Java
public class SomeClass {
public void someMethod() {
if (xxx) {
}
}
}
```
```Java
// Incorrect
if (expression)
// some code
// Correct
if (expression) {
// some code
}
```
--------------------------------
### JSP Taglib Declaration
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/install.md
Declare the displaytag tag library in your JSP pages using the taglib directive. This makes the display tags available for use.
```html
<%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
```
--------------------------------
### Referencing a List Bean by Name
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_sources.md
This attribute specifies the name of the bean in the request scope that holds the data for the table.
```html
```
--------------------------------
### Accessing Nested Properties in Non-EL Syntax
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_sources.md
Demonstrates accessing a nested property within a bean, including mapped and indexed properties, across different scopes. The default scope is requestScope.
```html
sessionScope.list.value.attribute(name).item[1]
```
--------------------------------
### Set Column Header Title Directly
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/i18n.md
Specify the column header text directly using the 'title' attribute in the column tag.
```jsp
```
--------------------------------
### Displaytag Table with JSTL and Implicit Objects
Source: https://github.com/hazendaz/displaytag/blob/master/src/site/markdown/tut_implicitobjects.md
This snippet shows how to access implicit row objects and row numbers using JSTL tags like when an 'id' attribute is set on the display:table tag.
```html
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.