JSP Survey Library           SourceForge.net Logo

Changing Things In the Middle Of A Survey

Introduction
    List of Functions
Saving The Start and End Time
Checking the Number of Users

Introduction

To change data or to retrieve data in the middle of a survey, you can put a line of JSP into a page that will save and retrieve info. Make sure to put the line below the first line in the file, the "include" -- every line that uses surveyData or other bits of code need to go below the "include" line, which must always be the first line in JSP.

Before you use any surveyData methods, you should always call isLoggedIn() to check whether or not someone is logged in -- someone might not be logged in if they jump straight to this page. Usually, if a person isn't logged in and they hit the page, the surveypage tag will send them back to the login page -- but your code is probably above the surveypage tag. But to make sure you don't throw an exception or do something incorrectly, you should check if they're logged in before doing anything, and if you don't check, and no one is logged in you'll recieve a warning message by email.
For example:


<%
if (isLoggedIn()) {// to make sure the user's logged in before we do this
/**Any Code Using surveyData goes here**/
}
%>

 

Survey Functions

Method/Function
What It Does Examples

isLoggedIn()
Returns true if someone is logged in, returns false if no one is logged in.
See Saving the Start and End Time

getUserID()
Returns the UserID of the current user -- in the form of "5", "23", etc.
 
  redirectTo(String page) Jump to another page. Make sure to use this as shown in the examples to the right.

Example 1: Jump to another page
<%
redirectTo("ShouldNotDoSurvey.jsp");
return; // always follow the above command with a "return;"
%>

Example 2: Branch to another page
<%
if (getData("Users", "Email").equals("BadUser@email.net")) {
    redirectTo("ShouldNotDoSurvey.jsp");
    return; // always follow the above command with a "return;"
}
%>

  getData(String table, String variableName)

Get data from the survey that this user has entered. Look up the table and the variable in the Survey Editor -- you can see the table as a property of the "page" and the question has the variable name (by default, "question1", "question2", etc.).

<%if (getData("Users", "Email").equals("Yoda-Boy@hello.net")) {
%>Hi Yoda!
<%}%>

  setData(String table, String variableName, Object newValue) Set a variable in the database for this user. See Saving the Start and End Time
  getRandomizer() Gets a RandomizeGenerator object, useful for doing randomizations.  
  getData(String table, String variableName, String repeatedMeasureVariable, Number repeatedMeasureValue)

getData(String table, String variableName, String repeatedMeasureVariable, String repeatedMeasureValue)

Works the same way as getData, above, except that you can use repeated measures -- if you have a repeated measure, pass in the page.  
  getData(String table, String variableName, String repeatedMeasureVariable, Object repeatedMeasureValue, Object newValue) Works the same was as setData, above, except that you can use a repeated measure and set the value for just a single repeated measure row.  
  getAllUsersData(String table, String variableName) Get a List of all of the different answers for a particular variable.

<%
// This will print out
all Suggested Names
List suggestedNames = g
etAllUsersData("Answers", "SuggestedName");
for (int i=0; i<suggestedNames.size(); i++) {
    %><%=suggestedNames.get(i)%><%
}

}%>

  surveyData.getTable(String tableName) Get a raw table, with all data in it. This returns a DataTableModel, which you can use for all sorts of generic table manipulations.  

 

In an advanced form, you can use the "surveyData" object to access more methods. The "surveyData" object has a variety of ways you can get data from it, for example, several more surveyData.getData(...) methods -- you can see all of the methods in the JavaDoc documentation of SurveyData.

 

Saving the Start and End Time

To save the time a user starts (i.e. saving the time the user first hits the first page of the survey), you can put a line of JSP in your first page (by default, "page1.jsp").
To save the time a user starts,


<%
if (isLoggedIn()) // to make sure the user's logged in before we do this
if (getData("Users", "Started")==null) // to make sure the "Started" variable has not been filled out before
setData("Users", "Started", new Date());
%>

To save the time a user ends (or rather, the time, the user hits the last page, which shouldn't have any questions on it), you can put a line of JSP at the top of your last JSP page (by default, "doneWithSurvey.jsp"), that goes like this:


<%
if (isLoggedIn()) // to make sure the user's logged in before we do this
if (getData("Users", "Finished")==null) // to make sure the "Finished" variable has not been filled out before
setData("Users", "Finished", new Date());
%>

Checking the Number Of Users

You can check how many users have logged into the survey with getNumberOfUsers(). This will return a number.
So, for example, if you want to make sure only 40 people go past a certain page, you can edit your front page, index.jsp, and add this below the include line.


<%
if (getNumberOfUsers()>40) {
redirectTo("doneWithSurvey.jsp"); // make sure you upload the "doneWithSurvey.jsp" file and edit it to be what you want!
return; // this is recommended -- it means "skip the rest of this page!", so it won't do anything else on this page.
}
%>

 

 

 

  Home
Screenshots and Demos
Help
  Installing
Building A Survey
Using JSP
surveypage tag
Repeated Measures
Changing Data
Getting Data
Clustering Survey
Java Web Start
Developers
Download
Contributors