com.objectplanet.survey.plugin.interfaces
Interface IPluginValidator

All Known Subinterfaces:
IPluginRequiredValidator

public interface IPluginValidator

Interface that makes it possible to implement a custom validator.

A class that implements this interface will be called when the question edit screen is loaded. A simple setup will be added to the question edit screen, while an advanced setup screen appears as a popup window when clicking on the provided link.

Author:
Rikard Halvorsen
Created:
September 24, 2004

Field Summary
static int CUSTOM_VALIDATOR_QUESTION
          Validator type: Custom validator for question
 
Method Summary
 boolean canValidate(int customValidatorType)
          Returns whether the plugin can validate the type of validation, or not
 java.lang.String getAdvancedHTML(java.util.HashMap settings)
          Returns the advanced HTML setup to be placed in a popup window when user click on link in the question edit screen.
 java.lang.String getErrorMessage(java.util.HashMap settings)
          Gets the errorMessage to show from the settings hashmap.
 java.lang.String getJavaScriptFunction(int questionNo, java.util.HashMap settings)
          Gets the javaScriptFunction code for client side validation For example, for a plugin called FreeTextValidatorPlugin the returning javascript function call could be:
 java.lang.String getJavaScriptFunctionCall(int questionNo, java.util.HashMap settings)
          Gets the javaScriptFunctionCall name for client side validation This method must return a complete function call, including the function name and the parameters signature.
 java.lang.String getSimpleHTML(java.util.HashMap settings)
          Returns the simple HTML setup to be placed in the question edit screen.
 boolean validate(long sId, int qNo, long respId, java.util.HashMap settings)
          Validates the question based on the attributes and values set in the settings hashmap
 

Field Detail

CUSTOM_VALIDATOR_QUESTION

static final int CUSTOM_VALIDATOR_QUESTION
Validator type: Custom validator for question

See Also:
Constant Field Values
Method Detail

canValidate

boolean canValidate(int customValidatorType)
Returns whether the plugin can validate the type of validation, or not

Parameters:
customValidatorType - The type of custom validation
Returns:
Whether the plugin can validate or not

validate

boolean validate(long sId,
                 int qNo,
                 long respId,
                 java.util.HashMap settings)
Validates the question based on the attributes and values set in the settings hashmap

Parameters:
sId - Survey id
qNo - Question number
respId - Respondent id
settings - Attributes and values settings
Returns:
Returns if valid or not

getSimpleHTML

java.lang.String getSimpleHTML(java.util.HashMap settings)
Returns the simple HTML setup to be placed in the question edit screen. This code will be placed within a html-TD tag. The simple setup should be placed on one single line. NOTE: All input field names must start with the plugin class name, followed by the underscore character and finally the input name. For example, for a plugin called FreeTextValidatorPlugin the returning HTML-code could be:

 <table> <tr> <td> Free text max length: <INPUT TYPE=text
 name="FreeTextValidatorPlugin_freeTextMaxLength" value=""> </td> <td> Custom error
 message: <INPUT TYPE=text name="FreeTextValidatorPlugin_errorMessage" value=""> </td>
 </tr> </table>

 
Value for each of the input fields will be stored in the settings attribute, and the input fields should be filled with the typed in values. Make use of HtmlUtils.htmlEncode(String value) when getting input values from user. This will encode input value and avoid errors caused by users typing in unwanted characters that could affect the original html page. NOTE: A field for a custom error message is useful when you want to customize the error message for each question. Be also aware of that only one error message is allowed for a validator.

Parameters:
settings - Attributes and values settings
Returns:
The HTML code

getAdvancedHTML

java.lang.String getAdvancedHTML(java.util.HashMap settings)
Returns the advanced HTML setup to be placed in a popup window when user click on link in the question edit screen. If no advanced setup is provided by the plugin, this method should return null. This code will be placed within an html-TD tag. The advanced setup code can include more settings to validate than the simple setup, and this setup screen will allow more than one line. NOTE: All input field names must start with the plugin class name, followed by the underscore character and finally the input name. For example, for a plugin called FreeTextValidatorPlugin the returning HTML-code could be:

 <table> <tr> <td> Free text max length: <INPUT TYPE=text
 name="FreeTextValidatorPlugin_freeTextMaxLength" value=""> </td> </tr> <tr> <td>
 Word required: <INPUT TYPE=text name="FreeTextValidatorPlugin_wordRequired" value="">
 </td> </tr> <tr> <td> Custom error message: <INPUT TYPE=text
 name="FreeTextValidatorPlugin_errorMessage" value=""> </td> </tr> </table>

 
Value for each of the input fields will be stored in the settings attribute, and the input fields should be filled with the typed in values. Make use of HtmlUtils.htmlEncode(String value) when getting input values from user. This will encode input value and avoid errors caused by users typing in unwanted characters that could affect the original html page. NOTE: A field for a custom error message is useful when you want to customize the error message for each question. Be also aware of that only one error message is allowed for a validator. For advanced setup the error message should be a combination of all the possible validation errors.

Parameters:
settings - Attributes and values settings
Returns:
The HTML code

getErrorMessage

java.lang.String getErrorMessage(java.util.HashMap settings)
Gets the errorMessage to show from the settings hashmap.

Parameters:
settings - Attributes and values settings
Returns:
The errorMessage value

getJavaScriptFunctionCall

java.lang.String getJavaScriptFunctionCall(int questionNo,
                                           java.util.HashMap settings)
Gets the javaScriptFunctionCall name for client side validation This method must return a complete function call, including the function name and the parameters signature. For example, for a plugin called FreeTextValidatorPlugin the returning javascript function call could be:

 checkMaxLengthAndRequiredWord(form.q1_freetext, 20, 'objectplanet')

 
For the function call above, the parameter "form.q1_freetext" says which input field to validate, in this case the free text input field for question 1. Next, the number 20 indicates how many characters the free text is allowed to have. Finally, the string parameter says what word the free text should include, in this case the word "objectplanet". NOTE: The HTML utility class for the plugins, HtmlUtils, should be used to get the name of input fields to validate. In addition, make use of HtmlUtils.htmlEncode(String value) when getting input values from user. This will encode input value and avoid errors caused by users typing in unwanted characters that could affect the original html page.

Returns:
The javaScriptFunctionCall name

getJavaScriptFunction

java.lang.String getJavaScriptFunction(int questionNo,
                                       java.util.HashMap settings)
Gets the javaScriptFunction code for client side validation For example, for a plugin called FreeTextValidatorPlugin the returning javascript function call could be:

 function checkMaxLengthAndRequiredWord(field, maxLength, wordRequired) { if(field != null){
 if(field.value != null){ if(field.value.length > 0){ if(maxLength > 0 && field.value.length >
 maxLength){ return false; } if(wordRequired != null && field.value.indexOf(wordRequired) <
 0){ return false; } } } } return true; }

 

Returns:
The javaScriptFunction code

Copyright ? ObjectPlanet Inc. All Rights Reserved.

Built on December 20 2016