Resources

SAS® AppDev Studio 3.0 Developer's Site

TableView: Cell, Row, and Member Level Editing   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 tableViewEditing.
  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 #3 of the wizard. Select the SAS Taglib and TBeans (Version 2) option in the Options list. Leave the SAS Runtime Classes and SAS Taglib and TBeans (Version 3) selected. Proceed to 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 JDBCDefaultExampleControllerServlet.java file from the Files Tab of the Project Navigator.
  2. Change the jdbcQuery string from ENTER_QUERY_STRING_HERE to "select * from sasuser.class" - you might have to copy the class data set from sashelp to sasuser.
  3. Modify JDBCTableViewExampleControllerServlet to allow editing of the SASUSER.CLASS data set by adding adapter.setReadOnly(false) to the code.
    if (adapter == null){
    	try{
    		//Create the model adapter and set it on the session
    		adapter = new JDBCToTableModelAdapter(sas_JDBCConnection, jdbcQuery);
    		adapter.setReadOnly(false);
    		if (session != null){
    			session.setAttribute(SAS_MODEL, adapter);
    		}
    	}
    	catch(Exception e){
    		throw new RuntimeException(e);
    	}
    }
    

Step 2: Add components to the JSP file

The default JSP file will contain a TableViewComposite component.

Customization: Row Level Editing

Add a <sas:TableView> tag and a <sas:Edit> tag to allow row level editing.

<sas:TableViewComposite id="sas_TableView1" model="sas_model" actionProvider="sas_actionProvider"
                        scope="session">
   <sas:RelationalMenuBar />
   <sas:TableView>
      <sas:Edit enabled="true" />
   </sas:TableView>
</sas:TableViewComposite>

Customization: Member Level Editing

Modify the <sas:Edit> tag to allow for member level editing.

<sas:TableView>
   <sas:Edit enabled="true" singleRowEditing="false"/>
</sas:TableView>

Customization: Using a Cell Editor

  1. Add the following import to the top of the JDBCTableViewExampleControllerServlet.java file:
    import javax.swing.DefaultComboBoxModel;
    
  2. Modify the controller servlet to create the model to be used by the Gender combo box. The modified code snippet is shown below.
    if (session != null){
          sas_actionProvider = (HttpActionProvider)session.getAttribute(ACTION_PROVIDER);
          String items[] = {"F", "M"};
          DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(items);
    	
          session.setAttribute("sas_ComboBoxModel",comboBoxModel); 
    }
    
  3. Modify the JSP file to use a combo box for Gender, and specify that the comboBoxModel should be used.
    <sas:TableView>
       <sas:Edit enabled="true" />
       <sas:CellEditor startRow="1" endRow="-1" startColumn="2" endColumn="2">
          <sas:CellContentsChoiceBoxEditor model="sas_ComboBoxModel" />
       </sas:CellEditor>
    </sas:TableView>
    

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

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.