com.ibm.as400.util.servlet
Class HTMLFormConverter

java.lang.Object
  extended by com.ibm.as400.util.servlet.StringConverter
      extended by com.ibm.as400.util.servlet.HTMLFormConverter
All Implemented Interfaces:
HTMLConstants, Serializable

public class HTMLFormConverter
extends StringConverter
implements Serializable, HTMLConstants

The HTMLFormConverter class can be used to convert data from a RowData object to an array of HTML strings or forms.

Each row is converted to a String representation of a one-row HTML table tag that can then be used by a servlet to display the formatted row back to a browser. The one-row table contains the column headers and the data for the individual row.

HTMLFormConverter objects generate the following events:

The following example creates an HTMLFormConverter object and converts the row data to an array of forms (html strings).

  

// Create an HTMLFormConverter object. HTMLFormConverter converter = new HTMLFormConverter();

// Convert the row data.

// Assume the RowData object was created and initialized in a previous step. String[] html = converter.convert(rowdata);

The following examples creates an HTMLFormConverter object and converts the row data to an array of forms (one-row HTMLTable objects).

  

// Creates an HTMLFormConverter object. HTMLFormConverter converter = new HTMLFormConverter();

// Convert the row data. Assume the RowData object was created and initialized in a previous step. HTMLTable[] forms = converter.convertToForms(rowdata);

The following example creates an HTMLFormConverter object and sets the column header hyperlinks before doing the conversion.

  

// Create an HTMLFormConverter object with a border. HTMLFormConverter converter = new HTMLFormConverter(); converter.setBorderWidth(1);

// Create the rowdata. int numberOfColumns = 3; ListMetaData metadata = new ListMetaData(numberOfColumns); metadata.setColumnLabel(0, "Animal ID"); metadata.setColumnLabel(1, "Animal Name"); metadata.setColumnLabel(2, "Date of Birth"); ListRowData rowdata = new ListRowData(metadata);

// Add a row. Object[] data = { new Integer(123456), "Timberwolf", (new Date()).toString() }; rowdata.addRow(data);

// Create the header hyperlinks. HTMLHyperlink[] links = new HTMLHyperlink[numberOfColumns]; links[0] = new HTMLHyperlink("http://www.myZoo.com/IDList.html", "MyZoo Animal Identification List"); links[1] = new HTMLHyperlink("http://www.myZoo.com/animals.html", "MyZoo Animal List"); converter.setHeaderHyperlinks(links);

// Convert the rowdata. String[] html = converter.convert(rowdata); System.out.println(html[0]);

Here is the html output:

  <table border="1">
  <tr>
  <th><a href="http://www.myZoo.com/IDList.html">Animal ID</a></th>
  <td>123456</td>
  </tr>
  <tr>
  <th><a href="http://www.myZoo.com/animals.html">Animal Name</a></th>
  <td>Timberwolf</td>
  </tr>
  <tr>
  <th>Date of Birth</th>
  <td>Sun Mar 14 16:00:00 CDT 1999</td>
  </tr>
  </table>
  

Here is what the form will look like in the browser:

Animal ID 123456
Animal Name Timberwolf
Date of Birth Sun Mar 14 16:00:00 CDT 1999

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
 
Fields inherited from interface com.ibm.as400.util.html.HTMLConstants
ABSBOTTOM, ABSMIDDLE, BASELINE, BOTTOM, CAPITALS, CENTER, CIRCLE, DISC, JUSTIFY, LARGE_ROMAN, LEFT, LOWER_CASE, LTR, MIDDLE, NUMBERS, RIGHT, RTL, SMALL_ROMAN, SQUARE, TARGET_BLANK, TARGET_PARENT, TARGET_SELF, TARGET_TOP, TEXTTOP, TOP
 
Constructor Summary
Constructor and Description
HTMLFormConverter()
          Constructs a default HTMLFormConverter object.
 
Method Summary
Modifier and Type Method and Description
 void addActionCompletedListener(ActionCompletedListener listener)
          Adds an ActionCompletedListener.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener.
 void addSectionCompletedListener(SectionCompletedListener listener)
          Adds a SectionCompletedListener.
 void addVetoableChangeListener(VetoableChangeListener listener)
          Adds the VetoableChangeListener.
 HTMLTable[] convertToForms(RowData rowdata)
          Converts the specified rowdata to an array of forms (one-row HTML tables).
 String getAlignment()
          Returns the form alignment.
 int getBorderWidth()
          Returns the form border width.
 HTMLTableCaption getCaption()
          Returns the form caption.
 int getCellPadding()
          Returns the form cell padding in pixels.
 int getCellSpacing()
          Returns the form cell spacing in pixels.
 String getDirection()
          Returns the form text interpretation direction.
 HTMLHyperlink[] getHeaderHyperlinks()
          Returns the form header's hyperlinks.
 String getLanguage()
          Returns the language of the form.
 HTMLHyperlink getObjectHyperlink(RowData rowdata, int column)
          Returns the object's hyperlink at the specified column within the current row.
 HTMLHyperlink getObjectHyperlink(RowData rowdata, int row, int column)
          Returns the object's hyperlink at the specified row and column.
 int getWidth()
          Returns the form width in pixels or percent.
 boolean isWidthInPercent()
          Indicates if the form width is in percent or pixels.
 void removeActionCompletedListener(ActionCompletedListener listener)
          Removes this ActionCompletedListener from the internal list.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes the PropertyChangeListener from the internal list.
 void removeSectionCompletedListener(SectionCompletedListener listener)
          Removes this SectionCompletedListener from the internal list.
 void removeVetoableChangeListener(VetoableChangeListener listener)
          Removes the VetoableChangeListener from the internal list.
 void setAlignment(String alignment)
          Sets the form alignment.
 void setBorderWidth(int borderWidth)
          Sets the form border width in pixels.
 void setCaption(HTMLTableCaption caption)
          Sets the form caption.
 void setCellPadding(int cellPadding)
          Sets the form cell padding in pixels.
 void setCellSpacing(int cellSpacing)
          Sets the form cell spacing in pixels.
 void setDirection(String dir)
          Sets the form text interpretation direction.
 void setHeaderHyperlinks(HTMLHyperlink[] links)
          Sets the form header's hyperlinks.
 void setLanguage(String lang)
          Sets the language of the form.
 void setObjectHyperlink(RowData rowdata, HTMLHyperlink link, int column)
          Sets the object's hyperlink at the specified column within the current row.
 void setObjectHyperlink(RowData rowdata, HTMLHyperlink link, int row, int column)
          Sets the object's hyperlink at the specified row and column.
 void setWidth(int width, boolean widthInPercent)
          Sets the form width in pixels or percent.
 
Methods inherited from class com.ibm.as400.util.servlet.StringConverter
convert
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTMLFormConverter

public HTMLFormConverter()
Constructs a default HTMLFormConverter object.

Method Detail

addActionCompletedListener

public void addActionCompletedListener(ActionCompletedListener listener)
Adds an ActionCompletedListener. The specified ActionCompletedListener's actionCompleted method is called each time the form conversion is complete. The ActionCompletedListener object is added to an internal list of ActionCompletedListeners; it can be removed with removeActionCompletedListener.

Parameters:
listener - The ActionCompletedListener.
See Also:
removeActionCompletedListener(com.ibm.as400.access.ActionCompletedListener)

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener. The specified PropertyChangeListener's propertyChange method is called each time the value of any bound property is changed.

Parameters:
listener - The PropertyChangeListener.
See Also:
removePropertyChangeListener(java.beans.PropertyChangeListener)

addSectionCompletedListener

public void addSectionCompletedListener(SectionCompletedListener listener)
Adds a SectionCompletedListener. The specified SectionCompletedListener's sectionCompleted method is called each time the conversion of a single row to a form is complete. The SectionCompletedListener object is added to an internal list of SectionCompletedListeners; it can be removed with removeSectionCompletedListener.

Parameters:
listener - The SectionCompletedListener.
See Also:
removeSectionCompletedListener(com.ibm.as400.util.servlet.SectionCompletedListener)

addVetoableChangeListener

public void addVetoableChangeListener(VetoableChangeListener listener)
Adds the VetoableChangeListener. The specified VetoableChangeListener's vetoableChange method is called each time the value of any constrained property is changed.

Parameters:
listener - The VetoableChangeListener.
See Also:
removeVetoableChangeListener(java.beans.VetoableChangeListener)

convertToForms

public HTMLTable[] convertToForms(RowData rowdata)
                           throws PropertyVetoException,
                                  RowDataException
Converts the specified rowdata to an array of forms (one-row HTML tables). Each form is a one-row HTML table with the column headers and the data of the individual row.

Parameters:
rowdata - The row data.
Returns:
An array of HTML tables.
Throws:
PropertyVetoException - If a change is vetoed.
RowDataException - If a row data error occurs.

getAlignment

public String getAlignment()
Returns the form alignment.

Returns:
The form alignment.

getBorderWidth

public int getBorderWidth()
Returns the form border width.

Returns:
The width in pixels.

getCaption

public HTMLTableCaption getCaption()
Returns the form caption.

Returns:
An HTMLTableCaption object that contains the form caption.

getCellPadding

public int getCellPadding()
Returns the form cell padding in pixels.

Returns:
The cell padding.

getCellSpacing

public int getCellSpacing()
Returns the form cell spacing in pixels.

Returns:
The cell spacing.

getDirection

public String getDirection()
Returns the form text interpretation direction.

Returns:
The direction.

getHeaderHyperlinks

public HTMLHyperlink[] getHeaderHyperlinks()
Returns the form header's hyperlinks.

Returns:
The hyperlinks.

getLanguage

public String getLanguage()
Returns the language of the form.

Returns:
The language.

getObjectHyperlink

public HTMLHyperlink getObjectHyperlink(RowData rowdata,
                                        int column)
Returns the object's hyperlink at the specified column within the current row.

Parameters:
rowdata - The RowData object that contains the data.
column - The column number (0-based).
Returns:
The hyperlink.

getObjectHyperlink

public HTMLHyperlink getObjectHyperlink(RowData rowdata,
                                        int row,
                                        int column)
Returns the object's hyperlink at the specified row and column.

Parameters:
rowdata - The RowData object that contains the data.
row - The row number (0-based).
column - The column number (0-based).
Returns:
The hyperlink.

getWidth

public int getWidth()
Returns the form width in pixels or percent.

Returns:
The form width.
See Also:
isWidthInPercent()

isWidthInPercent

public boolean isWidthInPercent()
Indicates if the form width is in percent or pixels.

Returns:
True if percent, false if pixels.
See Also:
getWidth()

removeActionCompletedListener

public void removeActionCompletedListener(ActionCompletedListener listener)
Removes this ActionCompletedListener from the internal list. If the ActionCompletedListener is not on the list, nothing is done.

Parameters:
listener - The ActionCompletedListener.
See Also:
addActionCompletedListener(com.ibm.as400.access.ActionCompletedListener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes the PropertyChangeListener from the internal list. If the PropertyChangeListener is not on the list, nothing is done.

Parameters:
listener - The PropertyChangeListener.
See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)

removeSectionCompletedListener

public void removeSectionCompletedListener(SectionCompletedListener listener)
Removes this SectionCompletedListener from the internal list. If the SectionCompletedListener is not on the list, nothing is done.

Parameters:
listener - The SectionCompltedListener.
See Also:
addSectionCompletedListener(com.ibm.as400.util.servlet.SectionCompletedListener)

removeVetoableChangeListener

public void removeVetoableChangeListener(VetoableChangeListener listener)
Removes the VetoableChangeListener from the internal list. If the VetoableChangeListener is not on the list, nothing is done.

Parameters:
listener - The VetoableChangeListener.
See Also:
addVetoableChangeListener(java.beans.VetoableChangeListener)

setAlignment

public void setAlignment(String alignment)
                  throws PropertyVetoException
Sets the form alignment. The default value is LEFT.

Parameters:
alignment - The form alignment. One of the following constants defined in HTMLConstants: CENTER, LEFT, or RIGHT.
Throws:
PropertyVetoException - If the change is vetoed.
See Also:
HTMLConstants

setBorderWidth

public void setBorderWidth(int borderWidth)
                    throws PropertyVetoException
Sets the form border width in pixels. A value of zero indicates no border. The default value is zero.

Parameters:
borderWidth - The border width in pixels.
Throws:
PropertyVetoException - If the change is vetoed.

setCaption

public void setCaption(HTMLTableCaption caption)
                throws PropertyVetoException
Sets the form caption.

Parameters:
caption - The caption text.
Throws:
PropertyVetoException - If the change is vetoed.

setCellPadding

public void setCellPadding(int cellPadding)
                    throws PropertyVetoException
Sets the form cell padding in pixels. The cell padding is the spacing between data in the form and the border of the form cell. The default value is zero (browser default used).

Parameters:
cellPadding - The cell padding in pixels.
Throws:
PropertyVetoException - If the change is vetoed.

setCellSpacing

public void setCellSpacing(int cellSpacing)
                    throws PropertyVetoException
Sets the form cell spacing in pixels. The cell spacing is the spacing between the form cells. The default value is zero (browser default used).

Parameters:
cellSpacing - The cell spacing in pixels.
Throws:
PropertyVetoException - If the change is vetoed.

setDirection

public void setDirection(String dir)
                  throws PropertyVetoException
Sets the form text interpretation direction.

Parameters:
dir - The direction of text interpretation. One of the following constants defined in HTMLConstants: LTR or RTL
Throws:
PropertyVetoException - If the change is vetoed.
See Also:
HTMLConstants

setHeaderHyperlinks

public void setHeaderHyperlinks(HTMLHyperlink[] links)
                         throws PropertyVetoException
Sets the form header's hyperlinks.

Parameters:
links - The hyperlinks.
Throws:
PropertyVetoException - If the change is vetoed.

setLanguage

public void setLanguage(String lang)
                 throws PropertyVetoException
Sets the language of the form.

Parameters:
lang - The language. Example language tags include: en and en-US.
Throws:
PropertyVetoException - If the change is vetoed.

setObjectHyperlink

public void setObjectHyperlink(RowData rowdata,
                               HTMLHyperlink link,
                               int column)
                        throws RowDataException
Sets the object's hyperlink at the specified column within the current row.

Parameters:
rowdata - The RowData object that contains the data.
link - The hyperlink.
column - The column number (0-based).
Throws:
RowDataException - If a row data error occurs.

setObjectHyperlink

public void setObjectHyperlink(RowData rowdata,
                               HTMLHyperlink link,
                               int row,
                               int column)
                        throws RowDataException
Sets the object's hyperlink at the specified row and column.

Parameters:
rowdata - The RowData object that contains the data.
link - The hyperlink.
row - The row number (0-based).
column - The column number (0-based).
Throws:
RowDataException - If a row data error occurs.

setWidth

public void setWidth(int width,
                     boolean widthInPercent)
              throws PropertyVetoException
Sets the form width in pixels or percent.

Parameters:
width - The form width.
widthInPercent - true if the width is specified as a percent; false if the width is specified in pixels.
Throws:
PropertyVetoException - If the change is vetoed.