osworkflow / docs / 3.5 Validators.html

Full commit
        <title>3.5 Validators</title>
	    <link rel="stylesheet" href="styles/site.css" type="text/css" />

	    <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff">
			    <td valign="top" class="pagebody">

				    <ul class="star">
<li> Back to <a href="3.4.4 Utility Functions.html">3.4.4 Utility Functions</a></li>
<li> Forward to <a href="3.6 Registers.html">3.6 Registers</a></li>
Just like <a href="3.4 Functions.html">3.4 Functions</a>, OSWorkflow allows for validators in three different forms: <b class="strong">Java-based</b>, <b class="strong">BeanShell</b>, and <b class="strong">BSF</b>. Java-based validators must implement the <b class="strong">com.opensymphony.workflow.Validator</b> interface (or in the case of <b class="strong">remote-ejb</b>&#039;s, the <b class="strong">com.opensymphony.workflow.ValidatorRemote</b> interface). With Java-based validators, throwing an InvalidInputException is all that is needed to mark an input as invalid and stop the workflow action from occuring. <p class="paragraph">But in BeanShell and BSF, things are a little different, since exceptions thrown in the scripts can&#039;t propogate out to the Java runtime environment. To get around this, any value returned in a BeanShell or BSF script will be used as the error message(s). The logic is as follows:
<ul class="star">
<li> If the value returned is an InvalidInputException object, that object is immediately thrown to the client</li>
<li> If the value returned is a Map, that Map is used for the error/errorMessage pairs in the InvalidInputException</li>
<li> If the value returned is a String[], the even numbers are used as keys, and the odd numbers are used as values to construct a Map that can then be used in the above case.</li>
<li> Otherwise, the value is converted to a String and added as a generic error message.</li>