|
MyGridListenerCustomImages.java
|
package com.dotj.test;
import com.dotj.grid.interfaces.*;
/**
* A custom dotJ grid listener implementation. A grid listener must implement the com.dotj.grid.interfaces.IGridListener<br>
* interface. In doing this, the various methods will be called when building the grid.
* <br><br>
* In this example, we perform three column level customizations using the columnBegin event.
*/
public class MyGridListenerCustomImages implements IGridListener {
// Whether to output some debug info for tracing and debugging purposes.
private boolean _columnDebug = false;
/**
* The <b>doCustomSort</b> method is used to tell the grid whether or not to physically sort the grid when building it. For
* example, if you are sorting your grid using a SQL WHERE clause, then you are in control of the sorting and can
* disable dotJ's internal sorting algorithm by returning a value of <code>true</code>.
*
* @param sortContext The context of the sort. This includes the column number being sorted and the sort type (ascending or descending).
* @return <code>true</code> if you are doing your own custom sorting, otherwise <code>false</code>.
*/
public boolean doCustomSort(ISortContext sortContext) {
return false;
}
/**
* The <b>rowBegin</b> method is called before dotJ builds the grid's row. This callback might be used to hilite a
* particular row based on a business rule.
*
* @param eventArgs The event being currently processed by the grid. For example, this could be a page or delete
* command.
* @param rowContext The context of the current row. This includes the row number, page number, stylesheet class,
* and the row's primary key field(s). Also, you can determine if this row is visible or selected.
*/
public void rowBegin(IGridCommandEventArgs eventArgs, IRowContext rowContext) {
}
/**
* The <b>rowEnd</b> method is called after dotJ builds the grid's row. This callback might be used to hilite a
* particular row based on a business rule.
*
* @param eventArgs The event being currently processed by the grid. For example, this could be a page or delete
* command.
* @param rowContext The context of the current row. This includes the row number, page number, stylesheet class,
* and the row's primary key field(s). Also, you can determine if this row is visible or selected.
*/
public void rowEnd(IGridCommandEventArgs eventArgs, IRowContext rowContext) {
}
/**
* The <b>columnBegin</b> method is called before dotJ builds the current row and column's cell. This callback can be
* used to modify the contents or look and feel of a single cell in the grid.
*
* @param rowContext The context of the current row. This includes the row number, page number, stylesheet class,
* and the row's primary key field(s). Also, you can determine if this row is visible or selected.
* @param columnContext The context of the current column (or cell). This includes the column number, stylesheet class,
* and column type. We also expose the cell's inner and outer HTML, which can be modified. In
* addition, the cell's raw value and formatted value is accessible.
* @param tag The column as declared in the JSP.
*/
public void columnBegin(IRowContext rowContext, IColumnContext columnContext, IColumnTag tag) {
if (_columnDebug) {
System.out.println("[Listener.ColBegin] COLUMN=" + columnContext.getColumnNumber() +
", TAG LABEL=" + tag.getLabel() +
", VISIBLE=" + columnContext.isColumnVisible() +
", STYLE=" + columnContext.getColumnStyleClass() +
", TYPE=" + columnContext.getColumnType() +
", RAW VALUE=" + columnContext.getCellRawValue() +
", FORMATTED VALUE=" + columnContext.getCellFormattedValue() +
", INNERHTML=" + columnContext.getCellInnerHTML() +
", OUTERHTML=" + columnContext.getCellOuterHTML());
}
// Overlay the value of the first column with the current row number.
if (columnContext.getColumnNumber() == 1) {
columnContext.overlayColumnValue("" + rowContext.getRowNumber());
}
// Customize the row's image icon based on whether it's an odd or even row number.
if (columnContext.getColumnNumber() == 2) {
String dataValue = (String) rowContext.getCellRawValue("name");
if ((rowContext.getRowNumber() % 2) == 0) {
columnContext.overlayColumnValue("<img src='/taglib/grid/msg.gif' title='" + dataValue + "' border='0'>");
} else {
columnContext.overlayColumnValue("<img src='/taglib/grid/excel.gif' title='" + dataValue + "' border='0'>");
}
}
// Hilite the user cell value if the value of the cell is "support".
if (columnContext.getColumnNumber() == 5) {
String dataValue = (String) rowContext.getCellRawValue("username");
if (dataValue != null && dataValue.equalsIgnoreCase("support")) {
columnContext.setColumnStyleClass(columnContext.getColumnStyleClass() + " HiliteCell");
}
}
}
/**
* The <b>columnEnd</b> method is called after dotJ builds the current row and column's cell. This callback can be
* used to modify the contents or look and feel of a single cell in the grid.
*
* @param rowContext The context of the current row. This includes the row number, page number, stylesheet class,
* and the row's primary key field(s). Also, you can determine if this row is visible or selected.
* @param columnContext The context of the current column (or cell). This includes the column number, stylesheet class,
* and column type. We also expose the cell's inner and outer HTML, which can be modified. In
* addition, the cell's raw value and formatted value is accessible.
* @param tag The column as declared in the JSP.
*/
public void columnEnd(IRowContext rowContext, IColumnContext columnContext, IColumnTag tag) {
if (_columnDebug) {
System.out.println("[Listener.ColEnd] COLUMN=" + columnContext.getColumnNumber() +
", TAG LABEL=" + tag.getLabel() +
", VISIBLE=" + columnContext.isColumnVisible() +
", STYLE=" + columnContext.getColumnStyleClass() +
", TYPE=" + columnContext.getColumnType() +
", RAW VALUE=" + columnContext.getCellRawValue() +
", FORMATTED VALUE=" + columnContext.getCellFormattedValue() +
", INNERHTML=" + columnContext.getCellInnerHTML() +
", OUTERHTML=" + columnContext.getCellOuterHTML());
}
}
}