| Form Elements: Client-Side Validation |
|
|
Data Source: JDBC
This example has two prerequisites:
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.
In order for this example to work properly, you must create the sasuser.houses data set. Open SAS and copy the following code into the editor window. Submit the statements from within SAS to create the sasuser.houses data set.
data sasuser.houses(label = 'Residential housing for sale' );
input style $ 1-8 sqfeet 10-13 bedrooms 15
baths 17-19 street $ 21-36 price 40-45;
label style = "Style of homes"
sqfeet = "Square footage"
bedrooms = "Number of bedrooms"
baths = "Number of bathrooms"
street = "Street address"
price = "Asking price";
format price dollar12.;
informat price comma12.;
cards;
RANCH 1250 2 1 Sheppard Avenue 64000
SPLIT 1190 1 1 Rand Street 65850
CONDO 1400 2 1.5 Market Street 80050
TWOSTORY 1810 4 3 Garris Street 107250
RANCH 1500 3 3 Kemble Avenue 86650
SPLIT 1615 4 3 West Drive 94450
SPLIT 1305 3 1.5 Graham Avenue 73650
CONDO 1390 3 2.5 Hampshire Avenue 79350
TWOSTORY 1040 2 1 Sanders Road 55850
CONDO 2105 4 2.5 Jeans Avenue 127150
RANCH 1535 3 3 State Highway 89100
TWOSTORY 1240 2 1 Fairbanks Circle 69250
RANCH 720 1 1 Nicholson Drive 34550
TWOSTORY 1745 4 2.5 Highland Road 102950
CONDO 1860 2 2 Arcata Avenue 110700
run;
In order for this example to work properly, you must create the sasuser.states data set. Open SAS and copy the following code into the editor window. Submit the statements from within SAS to create the sasuser.states data set.
data sasuser.states(label = 'US States'); input name $ 1-20 code $ 22-23; label name = "State Name" code = "State Code"; cards; Alabama AL Alaska AK Arizona AZ Arkansas AK California CA Colorado CO Connecticut CT District of Columbia DC Delaware DE Florida FL Georgia GA Hawaii HI Iowa IA Idaho ID Illinois IL Indiana IN Kansas KS Kentucky KY Louisiana LA Massachusetts MA Maryland MD Maine ME Michigan MI Minnesota MN Missouri MO Mississippi MS Montana MT Nebraska NE New Hampshire NH New Jersey NJ New Mexico NM New York NY Nevada NV North Carolina NC North Dakota ND Ohio OH Oklahoma OK Oregon OR Pennsylvania PA Rhode Island RI South Carolina SC South Dakota SD Tennessee TN Texas TX Utah UT Virginia VA Vermont VT Washington WA Wisconsin WI West Virginia WV Wyoming WY ; run;
Form.JDBCDefaultExampleControllerServlet.java file from the
Files Tab of the Project Navigator.
import com.sas.storage.jdbc.JDBCToComboBoxModelAdapter;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ComboBoxModel;
import com.sas.servlet.tbeans.models.JavaScriptNode;
import java.sql.*;
import java.util.Map;
private static final String STATE_ADAPTER = "state_adapter"; private static final String STATE_MODEL = "state_model"; private static final String STYLE_MODEL = "style_model"; private static final String BATH_MODEL = "bath_model"; private static final String BED_MODEL = "bed_model";
jdbcQuery string and add the following query string
variables as follows:
String jdbcQuery = "select * from sasuser.houses"; String stateComboQuery = "select * from sasuser.states"; String jdbcStyleQuery = "select distinct style from sasuser.houses"; String jdbcBedQuery = "select distinct bedrooms from sasuser.houses"; String jdbcBathQuery = "select distinct baths from sasuser.houses";
JDBCToComboBoxModelAdapter adapter = null; DefaultComboBoxModel adapter2 = new DefaultComboBoxModel(); DefaultComboBoxModel newStateModel = new DefaultComboBoxModel(); JDBCToComboBoxModelAdapter stateComboAdapter = null; JDBCToComboBoxModelAdapter styleComboAdapter = null; JDBCToComboBoxModelAdapter bathComboAdapter = null; JDBCToComboBoxModelAdapter bedComboAdapter = null;
adapter = (JDBCToComboBoxModelAdapter)session.getAttribute(SAS_MODEL); stateComboAdapter = (JDBCToComboBoxModelAdapter)session.getAttribute(STATE_ADAPTER); newStateModel = (DefaultComboBoxModel)session.getAttribute(STATE_MODEL); styleComboAdapter = (JDBCToComboBoxModelAdapter)session.getAttribute(STYLE_MODEL); bedComboAdapter = (JDBCToComboBoxModelAdapter)session.getAttribute(BED_MODEL); bathComboAdapter = (JDBCToComboBoxModelAdapter)session.getAttribute(BATH_MODEL);
if (adapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
adapter = new JDBCToComboBoxModelAdapter(sas_JDBCConnection, jdbcQuery);
//Set it on the session
if (session != null){
session.setAttribute(SAS_MODEL, adapter);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
if (stateComboAdapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
stateComboAdapter =
new JDBCToComboBoxModelAdapter(sas_JDBCConnection, stateComboQuery);
if(newStateModel == null)
newStateModel = new DefaultComboBoxModel();
for(int i=0; i < stateComboAdapter.getSize(); i++)
{
JavaScriptNode node = new JavaScriptNode();
node.setText((String)stateComboAdapter.getElementAt(i));
newStateModel.addElement(node);
}
//Set it on the session
if (session != null){
session.setAttribute(STATE_ADAPTER, stateComboAdapter);
session.setAttribute(STATE_MODEL, newStateModel);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
if (styleComboAdapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
styleComboAdapter =
new JDBCToComboBoxModelAdapter(sas_JDBCConnection, jdbcStyleQuery);
//Set it on the session
if (session != null){
session.setAttribute(STYLE_MODEL, styleComboAdapter);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
if (bedComboAdapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
bedComboAdapter =
new JDBCToComboBoxModelAdapter(sas_JDBCConnection, jdbcBedQuery);
//Set it on the session
if (session != null){
session.setAttribute(BED_MODEL, bedComboAdapter);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
if (bathComboAdapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
bathComboAdapter =
new JDBCToComboBoxModelAdapter(sas_JDBCConnection, jdbcBathQuery);
//Set it on the session
if (session != null){
session.setAttribute(BATH_MODEL, bathComboAdapter);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
package servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.sas.actionprovider.HttpActionProvider;
import com.sas.storage.jdbc.JDBCConnection;
import com.sas.storage.jdbc.JDBCAdapter;
import com.sas.storage.jdbc.JDBCToComboBoxModelAdapter;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ComboBoxModel;
import com.sas.servlet.tbeans.models.JavaScriptNode;
import java.sql.*;
import java.util.Map;
public class JDBCDefaultExampleControllerServlet
extends javax.servlet.http.HttpServlet
{
//Global Web application Strings
private static final String ACTION_PROVIDER = "sas_actionProvider";
//Global Web application JDBC variables
private static final String SAS_MODEL = "sas_model";
private static final String STATE_ADAPTER = "state_adapter";
private static final String STATE_MODEL = "state_model";
private static final String STYLE_MODEL = "style_model";
private static final String BATH_MODEL = "bath_model";
private static final String BED_MODEL = "bed_model";
private static final String JDBC_CONNECTION = "sas_JDBCConnection";
private static final String JDBC_DRIVER_NAME = "com.sas.rio.MVADriver";
private static final String JDBC_DATABASE_URL = "jdbc:sasiom://YOUR_LOCAL_MACHINE_NAME:5310";
/*
* doPost()
* Respond to the Post message.
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// Note: Calling doGet to provide same behavior to POST and GET HTTP methods.
doGet(request, response);
}
/*
* doGet()
* Respond to the Get message.
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
// Note: Add User DO_GET code here
HttpSession session = request.getSession();
// Setup the ActionProvider
HttpActionProvider sas_actionProvider = null;
synchronized (session) {
if (session != null){
sas_actionProvider = (HttpActionProvider)session.getAttribute(ACTION_PROVIDER);
}
//if ActionProvider is null, create one and put it on the session
if (sas_actionProvider == null) {
sas_actionProvider = new com.sas.actionprovider.HttpActionProvider();
sas_actionProvider.setLocale(request.getLocale());
sas_actionProvider.setControllerURL(request.getContextPath() + "/JDBCDefaultExampleControllerServlet");
sas_actionProvider.setName(ACTION_PROVIDER);
// store object in its scope
if (session != null)
session.setAttribute(ACTION_PROVIDER, sas_actionProvider);
}
//else execute the ActionProvider command
else{
sas_actionProvider.executeCommand(request, response, response.getWriter());
}
}
synchronized (session) {
//Setup the JDBC connection
JDBCConnection sas_JDBCConnection = null;
if (session != null){
sas_JDBCConnection = (JDBCConnection)session.getAttribute(JDBC_CONNECTION);
}
if (sas_JDBCConnection == null){
try{
sas_JDBCConnection = new JDBCConnection();
sas_JDBCConnection.setDriverName(JDBC_DRIVER_NAME);
sas_JDBCConnection.setDatabaseURL(JDBC_DATABASE_URL);
ServletConfig sc = getServletConfig();
sas_JDBCConnection.setUsername(sc.getInitParameter("metadata-userid"));
sas_JDBCConnection.setPassword(sc.getInitParameter("metadata-password"));
session.setAttribute(JDBC_CONNECTION, sas_JDBCConnection);
}
catch(Exception e){
throw new RuntimeException(e);
}
}
//Setup the query for the connection, such as "select * from sashelp.class"
String jdbcQuery = "select * from sasuser.houses";
String stateComboQuery = "select * from sasuser.states";
String jdbcStyleQuery = "select distinct style from sasuser.houses";
String jdbcBedQuery = "select distinct bedrooms from sasuser.houses";
String jdbcBathQuery = "select distinct baths from sasuser.houses";
//Setup the JDBC model adapter
JDBCToComboBoxModelAdapter adapter = null;
DefaultComboBoxModel adapter2 = new DefaultComboBoxModel();
DefaultComboBoxModel newStateModel = new DefaultComboBoxModel();
JDBCToComboBoxModelAdapter stateComboAdapter = null;
JDBCToComboBoxModelAdapter styleComboAdapter = null;
JDBCToComboBoxModelAdapter bathComboAdapter = null;
JDBCToComboBoxModelAdapter bedComboAdapter = null;
if (session != null){
adapter = (JDBCToComboBoxModelAdapter)session.getAttribute(SAS_MODEL);
stateComboAdapter = (JDBCToComboBoxModelAdapter)session.getAttribute(STATE_ADAPTER);
newStateModel = (DefaultComboBoxModel)session.getAttribute(STATE_MODEL);
styleComboAdapter = (JDBCToComboBoxModelAdapter)session.getAttribute(STYLE_MODEL);
bedComboAdapter = (JDBCToComboBoxModelAdapter)session.getAttribute(BED_MODEL);
bathComboAdapter = (JDBCToComboBoxModelAdapter)session.getAttribute(BATH_MODEL);
}
if (adapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
adapter = new JDBCToComboBoxModelAdapter(sas_JDBCConnection, jdbcQuery);
//Set it on the session
if (session != null){
session.setAttribute(SAS_MODEL, adapter);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
if (stateComboAdapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
stateComboAdapter =
new JDBCToComboBoxModelAdapter(sas_JDBCConnection, stateComboQuery);
if(newStateModel == null)
newStateModel = new DefaultComboBoxModel();
for(int i=0; i < stateComboAdapter.getSize(); i++)
{
JavaScriptNode node = new JavaScriptNode();
node.setText((String)stateComboAdapter.getElementAt(i));
newStateModel.addElement(node);
}
//Set it on the session
if (session != null){
session.setAttribute(STATE_ADAPTER, stateComboAdapter);
session.setAttribute(STATE_MODEL, newStateModel);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
if (styleComboAdapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
styleComboAdapter =
new JDBCToComboBoxModelAdapter(sas_JDBCConnection, jdbcStyleQuery);
//Set it on the session
if (session != null){
session.setAttribute(STYLE_MODEL, styleComboAdapter);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
if (bedComboAdapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
bedComboAdapter =
new JDBCToComboBoxModelAdapter(sas_JDBCConnection, jdbcBedQuery);
//Set it on the session
if (session != null){
session.setAttribute(BED_MODEL, bedComboAdapter);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
if (bathComboAdapter == null){
try{
//Add code below to create the model adapter.
//See the com.sas.storage.jdbc package in the API for more details.
//INSERT_MODEL_ADAPTER_CODE_HERE
bathComboAdapter =
new JDBCToComboBoxModelAdapter(sas_JDBCConnection, jdbcBathQuery);
//Set it on the session
if (session != null){
session.setAttribute(BATH_MODEL, bathComboAdapter);
}
}
catch(Exception e){
throw new RuntimeException(e);
}
}
}
//Forward the request to the JSP for display
RequestDispatcher rd =
getServletContext().getRequestDispatcher("/JDBCDefaultExampleViewer.jsp");
rd.forward(request, response);
}
}
myImages
to hold the house logo image. From the About It page, click the right-mouse
button while the pointer is over the House Logo image. Select the Save
Picture As option and save the picture to the myImages
folder.<%@page import="com.sas.servlet.tbeans.util.validators.RequiredStringValidator" %> <%@page import="com.sas.servlet.tbeans.models.Item" %> <%@page import="javax.swing.DefaultComboBoxModel" %>
<center> <table> <tr> <td><img src="myImages/house1.gif" height="150" width="150"/></td> <td> <table> <tr><td align="center"><font color="saddlebrown"><h1>Hometown</h1></font></td></tr> <tr><td><font color="saddlebrown"><h1>Realty</h1></font></td></tr> </table> </td> </tr> </table> </center> <hr color="saddlebrown">
<sas:Form id="form" method="get" action="pushButtonSubmit.jsp" validationEnabled="true" >
<center> <h2>Customer Request Form</h2> </center>
<% RequiredStringValidator reqValidator = new RequiredStringValidator(); %>
<%
DefaultComboBoxModel sqFootModel = new DefaultComboBoxModel();
DefaultComboBoxModel priceModel = new DefaultComboBoxModel();
Item sqFoot1 = new Item();
sqFoot1.setText("less than 1,500 sq. ft.");
sqFoot1.setValue("< 1500");
Item sqFoot2 = new Item();
sqFoot2.setText("more than 1,500 sq. ft.");
sqFoot2.setValue(">= 1500");
Item price1 = new Item();
price1.setText("less than $75,000");
price1.setValue("< 75000");
Item price2 = new Item();
price2.setText("more than $75,000");
price2.setValue("> 75000");
sqFootModel.addElement(sqFoot1);
sqFootModel.addElement(sqFoot2);
priceModel.addElement(price1);
priceModel.addElement(price2);
pageContext.setAttribute("sqFootModel", sqFootModel);
pageContext.setAttribute("priceModel", priceModel);
%>
<center> <table border="0"> <tr> <td align="right" nowrap>First Name</td> <td><sas:TextEntry id="firstName"/> <% //To set a required validator on the firstName field firstName.setValidator(reqValidator); form.addComponent(firstName); //Must be done for validation to work %> </td> <td align="right" nowrap>Last Name</td> <td><sas:TextEntry id="lastName"/> <% //To set a required validator on the lastName field lastName.setValidator(reqValidator); form.addComponent(lastName); //Must be done for validation to work %> </td> <td align="right">Phone</td> <td><sas:TextEntry id="phone" /></td> </tr> <tr> <td align="right">Address</td> <td><sas:TextEntry id="address" /></td> <td align="right">City</td> <td><sas:TextEntry id="city"/></td> <td align="right">State</td> <td><sas:ComboBoxView id="state" model="state_model"/></td> <td> </td> </tr> <tr> <td align="right">Zip</td> <td><sas:TextEntry id="zip" size="9"/></td> <td nowrap>Email Address</td> <td><sas:TextEntry id="email" /></td> <td nowrap>Confirm Email:</td> <td><sas:TextEntry id="email2" /></td> </tr> </table> </center> <hr> <center> <h2>Home Search:</h2> </center> <center> <table> <tr> <td align="center"><h4>Style:</h4></td> <td><dir><h4>Bedrooms:</h4></dir></td> <td><dir><h4>Baths:</h4></dir></td> <td><dir><dir><h4>Sq. Footage:</h4></dir></dir></td> <td><dir><dir><h4>Price Range:</h4></dir></dir></td> </tr> <tr valign="top"> <td><sas:ChoiceBox id="styleChoice" model="style_model"/></td> <td align="center"><dir><sas:ChoiceBox id="bedChoice" model="bed_model"/></dir></td> <td align="center"><dir><sas:ChoiceBox id="bathChoice" model="bath_model"/></dir></td> <td align="left" nowrap> <dir><sas:Radio id="sqFootRadio" model="sqFootModel" selectedIndex="0"/></dir></td> <td align="left" nowrap> <dir><sas:Radio id="priceRadio" model="priceModel" selectedIndex="0"/></dir></td> </tr> </table> </center> <br> <hr> <center> <sas:PushButton id="pushButton1" text="Submit Search" type="submit" onClick="validateEmail(email,email2);"/> </center>
<script>
function validateEmail(email1, email2)
{
if (email1.value != email2.value){
alert("Please re-enter and confirm email address");
email1.focus();
event.returnValue = false;
return false;
}
}
</script>
<%@ taglib uri="http://www.sas.com/taglib/sas" prefix="sas" %>
<%@ page pageEncoding="UTF-8"%>
<html>
<%@page import="com.sas.servlet.tbeans.util.validators.RequiredStringValidator" %>
<%@page import="com.sas.servlet.tbeans.models.Item" %>
<%@page import="javax.swing.DefaultComboBoxModel" %>
<title>HTML Form Tag Example</title>
<head>
<link href="styles/sasComponents.css" rel="STYLESHEET" type="text/css">
<LINK REL=STYLESHEET HREF="styles/myCSS.css" TYPE="text/css">
</head>
<body>
<center>
<table>
<tr>
<td><img src="myImages/house1.gif" height="150" width="150"/></td>
<td>
<table>
<tr><td align="center"><font color="saddlebrown"><h1>Hometown</h1></font></td></tr>
<tr><td><font color="saddlebrown"><h1>Realty</h1></font></td></tr>
</table>
</td>
</tr>
</table>
</center>
<hr color="saddlebrown">
<sas:Form id="form" method="get" action="pushButtonSubmit.jsp" validationEnabled="true" >
<center>
<h2>Customer Request Form</h2>
</center>
<%
RequiredStringValidator reqValidator = new RequiredStringValidator();
%>
<%
DefaultComboBoxModel sqFootModel = new DefaultComboBoxModel();
DefaultComboBoxModel priceModel = new DefaultComboBoxModel();
Item sqFoot1 = new Item();
sqFoot1.setText("less than 1,500 sq. ft.");
sqFoot1.setValue("< 1500");
Item sqFoot2 = new Item();
sqFoot2.setText("more than 1,500 sq. ft.");
sqFoot2.setValue(">= 1500");
Item price1 = new Item();
price1.setText("less than $75,000");
price1.setValue("< 75000");
Item price2 = new Item();
price2.setText("more than $75,000");
price2.setValue("> 75000");
sqFootModel.addElement(sqFoot1);
sqFootModel.addElement(sqFoot2);
priceModel.addElement(price1);
priceModel.addElement(price2);
pageContext.setAttribute("sqFootModel", sqFootModel);
pageContext.setAttribute("priceModel", priceModel);
%>
<center>
<table border="0">
<tr>
<td align="right" nowrap>First Name</td><td><sas:TextEntry id="firstName"/>
<%
firstName.setValidator(reqValidator);
form.addComponent(firstName);
%>
</td>
<td align="right" nowrap>Last Name</td><td><sas:TextEntry id="lastName"/>
<%
lastName.setValidator(reqValidator);
form.addComponent(lastName);
%></td>
<td align="right">Phone</td>
<td><sas:TextEntry id="phone" /></td>
</tr>
<tr>
<td align="right">Address</td><td><sas:TextEntry id="address" /></td>
<td align="right">City</td><td><sas:TextEntry id="city"/></td>
<td align="right">State</td><td>
<sas:ComboBoxView id="state" model="state_model"/>
</td>
<td> </td>
</tr>
<tr>
<td align="right">Zip</td><td><sas:TextEntry id="zip" size="9"/></td>
<td nowrap>Email Address</td>
<td><sas:TextEntry id="email" /></td>
<td nowrap>Confirm Email:</td>
<td><sas:TextEntry id="email2" /></td>
</tr>
</table>
</center>
<hr>
<center>
<h2>Home Search:</h2>
</center>
<center>
<table>
<tr>
<td align="center"><h4>Style:</h4></td>
<td><dir><h4>Bedrooms:</h4></dir></td>
<td><dir><h4>Baths:</h4></dir></td>
<td><dir><dir><h4>Sq. Footage:</h4></dir></dir></td>
<td><dir><dir><h4>Price Range:</h4></dir></dir></td>
</tr>
<tr valign="top">
<td><sas:ChoiceBox id="styleChoice" model="style_model"/></td>
<td align="center"><dir><sas:ChoiceBox id="bedChoice" model="bed_model"/></dir></td>
<td align="center"><dir><sas:ChoiceBox id="bathChoice" model="bath_model"/></dir></td>
<td align="left" nowrap>
<dir><sas:Radio id="sqFootRadio" model="sqFootModel" selectedIndex="0"/></dir></td>
<td align="left" nowrap>
<dir><sas:Radio id="priceRadio" model="priceModel" selectedIndex="0"/></dir></td>
</tr>
</table>
</center>
<br>
<hr>
<center>
<sas:PushButton id="pushButton1" text="Submit Search" type="submit" onClick="validateEmail(email,email2);"/>
</center>
<%
// Write the form footer
//form.writeFooter(out);
%>
</sas:Form>
<script>
function validateEmail(email1, email2)
{
if (email1.value != email2.value){
alert("Please enter re-enter and confirm email address");
email1.focus();
event.returnValue = false;
return false;
}
}
</script>
</body>
</html>
pushButtonSubmit.jsp by selecting
File
New. Choose the Tag Library JavaServer Page
JSP template in the wizard.
Copy the following code into the pushButtonSubmit.jsp file:
<html>
<%@page import="com.sas.storage.jdbc.JDBCToTableModelAdapter" %>
<%@page import="com.sas.storage.jdbc.JDBCConnection" %>
<%@page import="java.util.Enumeration" %>
<%@page import="java.lang.String" %>
<%@page import="javax.servlet.http.*" %>
<%@page import="com.sas.servlet.tbeans.tableview.html.TableView" %>
<head>
<title>Submit PushButton Processing</title>
</head>
<body>
<%
String JDBC_CONNECTION = "sas_JDBCConnection";
String JDBC_DRIVER_NAME = "com.sas.rio.MVADriver";
String JDBC_DATABASE_URL = "jdbc:sasiom://localhost:5310";
JDBCConnection sas_JDBCConnection2 = null;
JDBCToTableModelAdapter resultsAdapter = null;
HttpSession session2 = request.getSession();
if (session2 != null){
sas_JDBCConnection2 = (JDBCConnection)session2.getAttribute(JDBC_CONNECTION);
}
if (sas_JDBCConnection2 == null){
try{
sas_JDBCConnection2 = new JDBCConnection();
sas_JDBCConnection2.setDriverName(JDBC_DRIVER_NAME);
sas_JDBCConnection2.setDatabaseURL(JDBC_DATABASE_URL);
ServletConfig sc2 = getServletConfig();
sas_JDBCConnection2.setUsername(sc2.getInitParameter("metadata-userid"));
sas_JDBCConnection2.setPassword(sc2.getInitParameter("metadata-password"));
session2.setAttribute(JDBC_CONNECTION, sas_JDBCConnection2);
}
catch(Exception e){
throw new RuntimeException(e);
}
}
String jdbcResultsQuery = "select * from sasuser.houses where style='"+
request.getParameter("styleChoice")+"'"+
" and bedrooms >="+request.getParameter("bedChoice")+" and baths >="+
request.getParameter("bathChoice") + "and sqfeet "+
request.getParameter("sqFootRadio")+" and price "+request.getParameter("priceRadio");
resultsAdapter = new JDBCToTableModelAdapter(sas_JDBCConnection2, jdbcResultsQuery);
out.println("<p>Hi "+request.getParameter("firstName")+
".</p> <p>Thank you for your home search. Your search results are summarized below.</p>");
TableView table = new TableView();
table.setBorderWidth(2);
table.setModel(resultsAdapter);
table.write(out);
%>
</body>
</html>
For more information and options, see Web Application Example Templates.
SAS AppDev Studio
Services
SAS V9.1
Start SAS V9.1 IOM Spawner.