com.sas.servlet.beans.html
Class Table

java.lang.Object
  |
  +--com.sas.Component
        |
        +--com.sas.servlet.beans.BaseTransformation
              |
              +--com.sas.servlet.beans.BaseTable
                    |
                    +--com.sas.servlet.beans.html.Table

public class Table
extends BaseTable

Transformation bean for creating HTML tables. See the BaseTable documentation for additional information.

The following example illustrates the use of the Table Transformation Bean. A new model that implements com.sas.table.StaticTableInterface will be created. In this case a com.sas.models.SimpleTable object will be used, but a com.sas.sasserver.dataset.DataSetInterface model can be used as well. Once the model is created the Table Transformation Bean can be used to represent the table (the HTML-specific Table Transformation Bean will be used).

 // Create an instance of the SimpleTable object
 com.sas.models.SimpleTable weather = new com.sas.models.SimpleTable();
 weather.initialize();

// Define the columns for the model
// Add the column for the day weather.addColumn(1, java.lang.String.class, null); weather.setColumnLabel(1, "Day");
// Add the column for the daily forecast weather.addColumn(2, java.lang.String.class, null); weather.setColumnLabel(2, "Forecast");
// Add the column for the temperature weather.addColumn(3, java.lang.Double.class, null); weather.setColumnLabel(3, "High temperature");
// Add the rows for Friday, Saturday, and Sunday weather.addRow(1); weather.setCell(1, 1, "Friday"); weather.setCell(1, 2, "Sunny"); weather.setCell(1, 3, new Double(76.2));
weather.addRow(2); weather.setCell(2, 1, "Saturday"); weather.setCell(2, 2, "Cloudy"); weather.setCell(2, 3, new Double(57.7));
weather.addRow(3); weather.setCell(3, 1, "Sunday"); weather.setCell(3, 2, "Stormy"); weather.setCell(3, 3, new Double(52.3));

Now that the model has been created the Table Transformation Bean can be used to read the data from the model and format the 2-dimensional table

Example: Use the default properties to format a table

JSP Page:

 <html>
 <body>
 <%
    // Create the weather model (shown above)
    ...

// Create the Table Transformation Bean com.sas.servlet.beans.TableInterface table = new com.sas.servlet.beans.html.Table();
// Set the model table.setModelInterface(weather);
// Output the table table.write(out); %> </body> </html>

HTML output:

 <html>
 <body>
 <TABLE>
 <tr><td>Friday</td><td>Sunny</td><td>76.2</td></tr>
 <tr><td>Saturday</td><td>Cloudy</td><td>57.7</td></tr>
 <tr><td>Sunday</td><td>Stormy</td><td>52.3</td></tr>
 </TABLE>
 </body>
 </html>
 

Browser Table:

 
FridaySunny76.2
SaturdayCloudy57.7
SundayStormy52.3

Example: Use properties to format a table. Shows how the column heading is set to use the label name for each column.

JSP Page:

 <html>
 <body>
 <%
    // Create the weather model (shown above)
    ...

// Create the Table Transformation Bean com.sas.servlet.beans.TableInterface table = new com.sas.servlet.beans.html.Table();
// Set the model table.setModelInterface(weather);
// Set properties table.setUseColumnHeadings(true); table.setColumnHeadingColumnFormat("#META_LABEL#"); table.setBorderWidth(1);
// Output the table table.write(out); %> </body> </html>

HTML output:

 <html>
 <body>
 <TABLE BORDER=1>
 <tr><th>Day</th><th>Forecast</th><th>High temperature</th></tr>
 <tr><td>Friday</td><td>Sunny</td><td>76.2</td></tr>
 <tr><td>Saturday</td><td>Cloudy</td><td>57.7</td></tr>
 <tr><td>Sunday</td><td>Stormy</td><td>52.3</td></tr>
 </TABLE>
 </body>
 </html>
 

Browser Table:

 
DayForecastHigh temperature
FridaySunny76.2
SaturdayCloudy57.7
SundayStormy52.3

In the previous examples the write() method created the entire table, including the table header, column headings, all of the rows, and the table footer. If more control is necessary it is possible to invoke each of these operations separately:

Example: Create a table by iterating through the model and setting the column format for each row. This example will alternate the background color of each row

JSP Page:

 <html>
 <body>
 <%
    // Create the weather model (shown above)
    ...

// Create the Table Transformation Bean com.sas.servlet.beans.TableInterface table = new com.sas.servlet.beans.html.Table();
// Set the model table.setModelInterface(weather);
// Set attributes table.setCellSpacing(0); table.setCellPadding(5);
// Create an array of colors to use. Must escape the '#' character String[] colors = new String[2]; colors[0] = "\\#FFFFFF"; colors[1] = "\\#CCE5FF";
// Keep track of the row number int rowNumber = 0;
// Write the table header table.writeTableHeader(out);
// Loop through the table until there are no more rows while (true) {
// Get the rowid, mod it with the number of colors, and set the // background color String bgcolor = colors[rowNumber % colors.length];
// Set the column format for all columns table.setColumnFormat("<td bgcolor=\"" + bgcolor + "\">##</td>");
// Increment the row number rowNumber++;
// Write an individual row. The row number is 1-based. try { table.writeRow(rowNumber, out); } catch (java.io.EOFException ex) { // EOFException thrown when the end of file has been reached break; } }
// Write the table footer table.writeTableFooter(out); %> </body> </html>

HTML output:

 <html>
 <body>
 <TABLE CELLSPACING=0 CELLPADDING=5>
 <tr><td bgcolor="#FFFFFF">Friday</td><td bgcolor="#FFFFFF">Sunny</td><td bgcolor="#FFFFFF">76.2</td></tr>
 <tr><td bgcolor="#CCE5FF">Saturday</td><td bgcolor="#CCE5FF">Cloudy</td><td bgcolor="#CCE5FF">57.7</td></tr>
 <tr><td bgcolor="#FFFFFF">Sunday</td><td bgcolor="#FFFFFF">Stormy</td><td bgcolor="#FFFFFF">52.3</td></tr>
 </TABLE>
 </body>
 </html>
 

Browser Table:

 
FridaySunny76.2
SaturdayCloudy57.7
SundayStormy52.3
BaseTable

See Also:
Serialized Form

Field Summary
static String DEFAULT_BEGIN_ROW_FORMAT
           
static String DEFAULT_COLUMN_HEADING_FORMAT
           
static String DEFAULT_DATA_FORMAT
           
static String DEFAULT_END_ROW_FORMAT
           
 
Fields inherited from class com.sas.servlet.beans.BaseTable
MARKER, MARKER_ESC, MARKER_META, MARKER_META_ROWID
 
Constructor Summary
Table()
          Construct a new Table object
Table(String name, ModelInterface model)
          Construct a new Table object
 
Method Summary
 String getDefaultBeginRowFormat()
          Gets the default format to begin a new table row.
 String getDefaultColumnFormat()
          Gets the default format to be applied to each data element in a row.
 String getDefaultColumnHeadingFormat()
          Gets the default format to be applied to each column heading.
 String getDefaultEndRowFormat()
          Gets the default format to end a table row.
 void writeTableFooter(PrintWriter out)
          Writes the table footer
 void writeTableHeader(PrintWriter out)
          Writes the table header
 
Methods inherited from class com.sas.servlet.beans.BaseTable
formatRow, getBeginRowFormat, getBorderWidth, getCell, getCellPadding, getCellSpacing, getColumnCount, getColumnFormat, getColumnFormat, getColumnFormat, getColumnFormat, getColumnHeadingColumnFormat, getColumnHeadingColumnFormat, getColumnHeadingFormat, getColumnIndex, getColumnIndex, getColumnInfo, getEndRowFormat, getMaxRows, getRequiredInterfaces, getRowFormat, getRowFormat, getUseColumnHeadings, getWidth, getWidthPercentage, hasRepeatingFormats, isLastWriteTruncated, isMetaTag, rowExists, setBeginRowFormat, setBorderWidth, setCellPadding, setCellSpacing, setColumnFormat, setColumnFormat, setColumnFormat, setColumnFormat, setColumnFormat, setColumnHeadingColumnFormat, setColumnHeadingColumnFormat, setColumnHeadingFormat, setEndRowFormat, setMaxRows, setModelInterface, setRowFormat, setRowFormat, setUseColumnHeadings, setWidth, setWidthPercentage, write, writeColumnHeadings, writeColumnHeadings, writeColumnHeadings, writeRow, writeRow, writeRow, writeTable, writeTableFooter, writeTableFooter, writeTableHeader, writeTableHeader
 
Methods inherited from class com.sas.servlet.beans.BaseTransformation
getCustomAttributes, getDescription, getName, getParent, getRequest, getResponse, setCustomAttributes, setDescription, setName, setParent, setRequest, setResponse, toString, write, write, write
 
Methods inherited from class com.sas.Component
addLink, addPropertyChangeListener, addVetoableChangeListener, anyPropertyChangeListeners, attachModel, attachView, beansIsDesignTime, beansSetDesignTime, clone, clone, detachModel, detachView, dumpComponent, firePropertyChange, firePropertyChange, fireVetoableChange, getComponentDescription, getComponentSupportInfo, getEventMethod, getEventValues, getExtendedBeanInfo, getLinkInfo, getModelInterface, getResources, getStringResource, getViewInterfaceSupportInfo, initialize, initializeComponent, isDesignTime, isLinked, propertyChange, queryLinks, queryLinks, refresh, removeAllLinks, removeInterfaceTraps, removeLink, removePropertyChangeListener, removeVetoableChangeListener, setComponentDescription, setComponentSupportInfo, setDefaultValues, setLinkInfo, setRequiredInterfaces, setViewInterfaceSupportInfo, supportsListenerInterface, supportsRequiredInterfaces, trapInterfaceEvents, validateObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BEGIN_ROW_FORMAT

public static final String DEFAULT_BEGIN_ROW_FORMAT

DEFAULT_DATA_FORMAT

public static final String DEFAULT_DATA_FORMAT

DEFAULT_END_ROW_FORMAT

public static final String DEFAULT_END_ROW_FORMAT

DEFAULT_COLUMN_HEADING_FORMAT

public static final String DEFAULT_COLUMN_HEADING_FORMAT
Constructor Detail

Table

public Table()
Construct a new Table object

Table

public Table(String name,
             ModelInterface model)
Construct a new Table object
Parameters:
name - The field name
Method Detail

getDefaultBeginRowFormat

public String getDefaultBeginRowFormat()
Gets the default format to begin a new table row.
Returns:
The default begin row format

getDefaultColumnFormat

public String getDefaultColumnFormat()
Gets the default format to be applied to each data element in a row. Use regular parameter markers with no name or index to indicate the location of the data (such as ##, or #META_NAME#)
Returns:
The default data format

getDefaultEndRowFormat

public String getDefaultEndRowFormat()
Gets the default format to end a table row.
Returns:
The default end row format

getDefaultColumnHeadingFormat

public String getDefaultColumnHeadingFormat()
Gets the default format to be applied to each column heading. Use regular parameter markers with no name or index to indicate the location of the meta data (such as #META_NAME#)
Returns:
The default column heading format

writeTableHeader

public void writeTableHeader(PrintWriter out)
                      throws IOException
Writes the table header
Parameters:
out - The output stream
Throws:
IOException - Thrown if some type of I/O error occurs

writeTableFooter

public void writeTableFooter(PrintWriter out)
                      throws IOException
Writes the table footer
Parameters:
out - The output stream
Throws:
IOException - Thrown if some type of I/O error occurs


Version: 1.2.20000317.001 Formatted: 2000/07/06 15:57:33PM