| Line Plot |
|
|
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.
LinePlotJSP.JDBCTableViewExampleControllerServlet.java
file from the Files Tab of the Project Navigator.
The JDBCTableViewExampleControllerServlet.java file contains servlet
code to get a JDBC connection to SAS data and build a relational data model
with a JDBCToTableModelAdapter.
Just below the existing import statements at the top of the
JDBCTableViewExampleControllerServlet.java file,
import the following classes:
import com.sas.graphics.components.lineplot.LinePlotTableDataModel; import com.sas.graphics.components.PlotVariable;
Scroll down to the global Web application strings and add the following string:
private static final String LINE_DATA_MODEL = "line_data_model";
jdbcQuery string and change ENTER_QUERY_STRING_HERE
to "select * from sashelp.class".jdbcQuery string creates the
JDBCToTableModelAdapter. You must add similar code to create the LinePlotTableDataModel.
You must then set the JDBCToTableModelAdapter as the model for the LinePlotTableDataModel,
and finally assign variable roles to the plot data model.
In the following code fragment, the code you must add is shown in bold. The code that is not bold provides a context that shows exactly where you should add your new code.
// Set up the JDBC model adapter
JDBCToTableModelAdapter adapter = null;
if (session != null){
adapter = (JDBCToTableModelAdapter)session.getAttribute(SAS_MODEL);
}
if (adapter == null){
try{
//Create the model adapter and set it on the session
adapter = new JDBCToTableModelAdapter(sas_JDBCConnection, jdbcQuery);
if (session != null){
session.setAttribute(SAS_MODEL, adapter);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
//Set up the LinePlotTableDataModel
LinePlotTableDataModel dataModel = null;
if (session != null){
dataModel = (LinePlotTableDataModel)session
.getAttribute(LINE_DATA_MODEL);
}
if (dataModel == null){
try{
// Create a data model for the plot
dataModel= new LinePlotTableDataModel();
if (session != null){
session.setAttribute(LINE_DATA_MODEL, dataModel);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
// Set the table model adapter on the data model
dataModel.setModel(adapter);
// Assign variable roles to the data model
dataModel.setXVariable(
new PlotVariable("Weight"));
dataModel.setYVariable(
new PlotVariable("Height"));
dataModel.setSortVariable(dataModel.getXVariable());
}
// Forward the request to the JSP for display
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/JDBCTableViewExampleViewer.jsp");
rd.forward(request, response);
When you used the WebApp Project Wizard to create this project, you selected JDBC TableView servlet as the type of initial content for the project. In response, the Wizard generated servlet code to build a relational data model, and it generated an JDBCTableViewExampleViewer.jsp file containing a <sas:TableViewComposite> element as the viewer for the data model.
JDBCTableViewExampleControllerServlet.java file.Replace the existing <sas:TableViewComposite> tag structure in JDBCTableViewExampleViewer.jsp with the following tag structure:
<sas:LinePlot id="linePlot1" model="line_data_model" >
<sas:LinePlotModel>
<sas:XAxisModel label="Weight in Pounds" />
<sas:YAxisModel label="Height in Inches" />
</sas:LinePlotModel>
</sas:LinePlot>
For more information and options, see Web Application Example Templates.
SAS AppDev Studio
Services
SAS V9.1
Start SAS V9.1 IOM Spawner.