Resources

SAS® AppDev Studio 3.0 Developer's Site

ActionProvider: Customizing the TableView Sort Actions   About It Build It  

Data Source: JDBC

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 CustomizeSortActions.
  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 JDBCTableViewExampleControllerServlet.java file from the Files Tab of the Project Navigator.
  2. Change the jdbcQuery string from ENTER_QUERY_STRING_HERE to "select * from sashelp.class".
  3. Add the following imports to the top of the JDBCTableViewExampleControllerServlet.java file.
    import com.sas.actionprovider.BaseAction;
    import com.sas.actionprovider.ActionOrderList;
    import com.sas.actionprovider.support.ActionProviderSupportTypes;
    import com.sas.actionprovider.support.tableview.HttpTableViewSupport;
    import com.sas.commands.relational.SortCommand;
    import com.sas.servlet.tbeans.StyleInfo;
    import com.sas.servlet.tbeans.dataselectors.html.RelationalMenuBar;
    import com.sas.servlet.tbeans.menubar.html.MenuBar;
    import com.sas.servlet.tbeans.tableview.html.TableView;
    import com.sas.servlet.tbeans.tableview.html.TableViewComposite;
    import java.util.HashMap;
    import java.util.Map;
    

Step 3: Add code to customize the sort actions

Add the following code at the end of and within the second synchronized block where the JDBCConnection and JDBCToTableModelAdapter are initialized.

// If we need instance of Table component when registering a custom ActionOrderList,
// instantiate the component here.
// See call to setActionOrderList() below.
TableViewComposite sas_TableView1 = null;
if (session != null){
	sas_TableView1 = (TableViewComposite)session.getAttribute("sas_TableView1");
}

if (sas_TableView1 == null){
	sas_TableView1 = new TableViewComposite();
	sas_TableView1.setModel(adapter);
	sas_TableView1.setActionProvider(sas_actionProvider);

	// Make the Menubar visible
	RelationalMenuBar mb =
     (RelationalMenuBar)sas_TableView1.getComponent(sas_TableView1.TABLEVIEW_MENUBAR);
	mb.setVisible(true);

	session.setAttribute("sas_TableView1", sas_TableView1);
}

// Create a custom ActionOrderList for the COLUMN_HEADER_AREA and add the
// appropriate actionTypes. All the default actionTypes that we are not including
// on this ActionOrderList ( e.g. MOVE_LEFT and MOVE_RIGHT ) will essentially be
// hidden to the viewer.
ActionOrderList columnHeaderAOL= new ActionOrderList(ActionOrderList.ROOT_NAME,3);
columnHeaderAOL.add(HttpTableViewSupport.SORT_COLUMN_ASCENDING_ACTION);
columnHeaderAOL.add(HttpTableViewSupport.SORT_COLUMN_DESCENDING_ACTION);
columnHeaderAOL.setEnabledIfEmpty(false);

// If custom ActionOrderList is suitable for all TableView components that use
// this instance of the ActionProvider, then we could specify null for the viewer argument
// instead of an instance of the TableView as we do here.
TableView table = (TableView)sas_TableView1.getComponent(sas_TableView1.TABLEVIEW_TABLEDATA);
sas_actionProvider.setActionOrderList(ActionProviderSupportTypes.TABLEVIEW_SUPPORT,
     columnHeaderAOL, table, HttpTableViewSupport.COLUMN_HEADER_AREA);

// Acquire the 'version' of the ascending sort action from which the APF clones all other
// versions that are returned to viewer components.
BaseAction sortAscendingAction =
     sas_actionProvider.getDefaultAction(ActionProviderSupportTypes.TABLEVIEW_SUPPORT,
         HttpTableViewSupport.COLUMN_HEADER_AREA,
         HttpTableViewSupport.SORT_COLUMN_ASCENDING_ACTION);

// Since either this Action or the sortDescendingAction will be taking the place of the
// COLUMN_HEADER_ACTION, we need to change the displayed text for this Action from
// "Sort Ascending" to the name of the column. This can be accomplished via the setting of
// a template string value that includes the AREA_VALUE_ATTRKEY. Such template values can be
// very useful in other scenarios where Action attribute values vary according to the specific
// area the Action is being used.
sortAscendingAction.putValue(sortAscendingAction.LABEL,
     "%"+HttpTableViewSupport.AREA_VALUE_ATTRKEY);

// Position the column name text to the left of the image.
sortAscendingAction.putValue(sortAscendingAction.TEXT_ALIGNMENT,
     sortAscendingAction.ALIGNMENT_LEFT);

// Set the Action's tooltip text.
sortAscendingAction.putValue(sortAscendingAction.SHORT_DESCRIPTION,
     "Ascending Sort Of %"+HttpTableViewSupport.AREA_VALUE_ATTRKEY+" Column");

// Only return this Action to the viewer component when it is in an enabled state.
sortAscendingAction.setReturnStatus(sortAscendingAction.ENABLED);

// The 'sortDescendingImage' dynamic value is only available when the column is sorted
// ascendingly. If that value is not available, then we do not want an image on this Action.
sortAscendingAction.putValue(sortAscendingAction.SMALL_ICON_NAME,
     "%sortDescendingImage(down_02b.gif)");

// Command should not be enabled ( and, consequently, the Action that uses it ) if the
// column is already sorted in this direction.
((SortCommand)sortAscendingAction.getCommand()).setDisabledIfCurrentState(true);

// .tableviewmenuLink not defined in default sasComponents.css so use the
// .tableviewmenuItemLink style class.
Map styleMap = new HashMap();
styleMap.put(MenuBar.MENU_LINK,new StyleInfo("menuItemLink"));
sortAscendingAction.putValue(sortAscendingAction.STYLE_MAP, styleMap);

// Do the same for the SORT_COLUMN_DESCENDING_ACTION
BaseAction sortDescendingAction =
     sas_actionProvider.getDefaultAction(ActionProviderSupportTypes.TABLEVIEW_SUPPORT,
         HttpTableViewSupport.COLUMN_HEADER_AREA,
         HttpTableViewSupport.SORT_COLUMN_DESCENDING_ACTION);
sortDescendingAction.putValue(sortDescendingAction.LABEL,
     "%"+HttpTableViewSupport.AREA_VALUE_ATTRKEY);
sortDescendingAction.putValue(sortAscendingAction.TEXT_ALIGNMENT,
     sortAscendingAction.ALIGNMENT_LEFT);
sortDescendingAction.putValue(sortAscendingAction.SHORT_DESCRIPTION,
    "Descending Sort Of %"+HttpTableViewSupport.AREA_VALUE_ATTRKEY+" Column");
sortDescendingAction.setReturnStatus(sortDescendingAction.ENABLED);
sortDescendingAction.putValue(sortDescendingAction.SMALL_ICON_NAME,
    "%sortAscendingImage(up_02b.gif)");
((SortCommand)sortDescendingAction.getCommand()).setDisabledIfCurrentState(true);
sortDescendingAction.putValue(sortAscendingAction.STYLE_MAP, styleMap);

Step 4: Add components to the JSP file

Replace the default TableViewComposite tag with the one below:

<%@ taglib uri="http://www.sas.com/taglib/sas" prefix="sas" %>
<%@ page pageEncoding="UTF-8"%>
<html>
<head>
<link href="styles/sasComponents.css" rel="STYLESHEET" type="text/css">
</head>

<body>
<sas:TableViewComposite id="sas_TableView1" model="sas_model" actionProvider="sas_actionProvider"
scope="session">
	<sas:RelationalMenuBar />
</sas:TableViewComposite>
</body>

</html>

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

Step 5: 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.