Resources

SAS® AppDev Studio 3.0 Developer's Site

Displaying a Table using JDBC   About It Build It  

Data Source: JDBC

This example includes the following customizations:

Please install the latest webAF template updates prior to building this example. For more information about the server-side example templates used by this example, see Web Application Example Templates and Built-in Web Application Templates and Options.

The following example is not meant to be a complete Web application, rather it is to show how to use a particular component(s). The example does not address the issue of immediately freeing up resources when the user navigates off the Web application or closes the Web browser. Any necessary resources created in the example will stay around until the associated HTTPSession times out. If this example is used in a multi-user environment, it is possible to exhaust the available resources until HTTPSessions time out and free up their associated resources.

Step 1: Create a project in webAF

  1. Create a new project named tableView.
  2. Select Web Application from the webAF Projects list.
  3. Accept the defaults as you go through the Web App wizard until you have reached step #4 of the wizard. At this step you will need to select Examples in the radio box titled Display list for. Choose JDBC TableView Servlet from the list box titled Type of initial content.
  4. Continue accepting defaults as you complete the Web App wizard.

Step 2: Set up access to the data source

  1. Open the JDBC Default ExampleControllerServlet.java file from the Files Tab of the Project Navigator.
  2. Change the jdbcQuery string from ENTER_QUERY_STRING_HERE to "select * from sashelp.prdsale".

Step 3: Add components to the JSP file

The default JSP file will contain a TableViewComposite component.

Customization: Controlling the number of rows and columns that display

Add the rowPageSize and columnPageSize attributes to the <sas:TableView> custom tag. The code is shown below.

<sas:TableViewComposite id="sas_TableView1" model="sas_model"
         actionProvider="sas_actionProvider" scope="session">
   <sas:RelationalMenuBar />
   <sas:TableView rowPageSize="10" columnPageSize="8"/>
</sas:TableViewComposite>

Customization: Using renderers to display rows with different background colors

Add a <sas:CellRenderer> tag to the example to color every other row with a gray background. The code is shown below.

<sas:TableView rowPageSize="10" columnPageSize="8" >
   <sas:CellRenderer bgColor="dcdcdc" startRow="1" endRow="-1" repeatRowFactor="2"
      startColumn="1" endColumn="-1" repeatColumnFactor="1">
   </sas:CellRenderer> 
</sas:TableView>

Customization: Using renderers to display columns with different colors and fonts

Modify the <sas:CellRenderer> inner tag to change the background color of column 7 to red. Add a <sas:CellContentsLabelRenderer> inner tag to the example in order to change the text font. The code is shown below.

<sas:CellRenderer bgColor="red" startRow="1" endRow="-1" repeatRowFactor="1" startColumn="7"
     endColumn="7" repeatColumnFactor="1">
   <sas:CellContentsLabelRenderer>
      <sas:StyleInfo style="font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif;
         font-size: 12pt;
         font-weight: bold;"/>
   </sas:CellContentsLabelRenderer>
</sas:CellRenderer>

For more information and options, see the Web Application Example Templates paper.

Step 4: Finish the project

  1. Build the project.
  2. Start the IOM Spawner by selecting Start Menu [arrow] SAS AppDev Studio [arrow] Services [arrow] SAS V9.1 [arrow] Start SAS V9.1 IOM Spawner.
  3. Start the Java Web server.
  4. Execute in browser.