validators -->
<workflow-components key="components" /> |
Callback on validator errorIt is possible to add a JavaScript function that will be called instead of displaying a system window when a validator reports an error. If the button has multiple validators, the errors (error boxes, variable underlining, etc.) from the usual validator errors are displayed first, and at that time the validators that reported the callback will be ignored. If the user has gotten rid of all the standard errors, each subsequent acceptance of the task will only call one single callback. To add a callback to a component, next to the annotation Javadoc |
---|
displayValue | Validator |
---|
property | javadoc.plusworkflow |
---|
className | com.suncode.pwfl.workflow.form.validator.annotation.Validator |
---|
| add an annotation Javadoc |
---|
displayValue | ValidatorsScript |
---|
property | javadoc.plusworkflow |
---|
className | com.suncode.pwfl.workflow.form.validator.annotation.ValidatorsScript |
---|
| specifying the path to the script (located in resources). Code Block |
---|
| @Validator
@ValidatorsScript( value = "scripts/peselValidatorCallback.js" )
public class PeselValidator |
To report a callback on the form, call invokeCallback with Javadoc |
---|
displayValue | ValidationErrors |
---|
property | javadoc.plusworkflow |
---|
className | com.suncode.pwfl.workflow.form.validator.error.ValidationErrors |
---|
| . Code Block |
---|
| public void validate( @Param( value = "param" ) Variable param, ValidationErrors errors )
{
//...
if ( validatorFailed )
{
errors.invokeCallback();
}
} |
If the validator simultaneously adds errors and reports a callback invocation, the errors will be ignored by the server (a JavaScript callback will be called). If the validator does not have annotation Javadoc |
---|
displayValue | ValidatorsScript |
---|
property | javadoc.plusworkflow |
---|
className | com.suncode.pwfl.workflow.form.validator.annotation.ValidatorsScript |
---|
| ,an exception will be thrown when invokeCallback is called. The implementation of callback in JavaScript is analogous to the creation of Actions scripts. Code Block |
---|
| PW.FormValidators.create('pesel-validator', {
callback : function() {
console.log('Pesel validator callback');
if(ignorePesel) {
this.confirm();
}
}
}); |
The first argument of the create function must be the same as the id of the validator. The second argument is the object that implements the callback method, which is called when an error is added to the validator. If you want to validate the validator to let the acceptance continue, you must call the validator method this.confirm(). If the validation is called, the callback of the next validator (if any) will automatically be called. Once all the callbacks have been validated, then the acceptance will happen, bypassing these validators. Forwarding an argument to a callback Warning |
---|
The functionality is not available yet. |
The invokeCallback method allows you to forward any object, which can then be used by a browser-side script. This object will be converted to JSON by the Jackson library. Example usage: Code Block |
---|
| Map<String, Object> exampleObject = new HashMap<String, Object>();
exampleObject.put( "prop1", "some text" );
exampleObject.put( "prop2", true );
exampleObject.put( "prop3", 23423 );
errors.invokeCallback( exampleObject ); |
JavaScript side: Code Block |
---|
| callback : function(exampleObject) {
console.log(exampleObject.prop1);
console.log(exampleObject.prop2);
console.log(exampleObject.prop3);
} |
Validation error or confirmation messageIt is possible to specify in the PWE a validation error message and a form acceptance confirmation message despite the validation error. In order to display these fields in the PWE, you need to specify in the validator builder which types of messages can be configured. Code Block |
---|
language | java |
---|
linenumbers | true |
---|
| @Validator
public class PeselValidator
{
private final String PESEL_REGEX = "^\\d{11}$";
@Define
public void definition( ValidatorDefinitionBuilder builder )
{
builder
.id( "pesel-validator" )
.name( "validator.pesel" )
.description( "validator.pesel.desc" )
.category( Categories.TEST )
.messageTypes( ValidatorMessage.CONFIRMATION, ValidatorMessage.ERROR ) // it will be possible to configure confirmation message and validation error
.parameter()
.id( "pesel_param" )
.name( "validator.pesel.parameter.name" )
.description( "validator.pesel.parameter.desc" )
.type( Types.VARIABLE)
.create();
}
//Metoda walidująca
public void validate( @Param( value = "pesel_param" ) Variable pesel, ValidationErrors errors,
Translator translator )
{
boolean isPesel = Pattern.matches( PESEL_REGEX, (String) pesel.getValue() );
if ( isPesel == false )
{
errors.add( translator.getMessage( "validator.pesel.invalid" ), pesel.getId() );
}
}
} |
Enum Javadoc |
---|
displayValue | ValidatorMessage |
---|
property | javadoc.plusworkflow |
---|
className | com.suncode.pwfl.workflow.form.validator.ValidatorMessage |
---|
| determines which messages can be configured in PWE. These messages act as parameters of String type, so it is possible to use values of variables, functions, etc. in them.In the execute method of the validator, it is possible to retrieve two new objects: Javadoc |
---|
displayValue | DefinedConfirmation |
---|
property | javadoc.plusworkflow |
---|
className | com.suncode.pwfl.workflow.form.validator.error.DefinedConfirmation |
---|
| - object storing title and confirmation text Javadoc |
---|
displayValue | DefinedError |
---|
property | javadoc.plusworkflow |
---|
className | com.suncode.pwfl.workflow.form.validator.error.DefinedError |
---|
| - object storing the text of the error
These objects should be added to errors and validation confirmations. Example usage: Code Block |
---|
| public void validate( @Param( value = "param" ) Variable param, ValidationErrors errors,
Translator translator, DefinedError error, DefinedConfirmation confirmation )
{
String value = param.getValue().toString();
if ( /* condition - validation error */ )
{
errors.add( error );
}
else if ( /* condition - despite the error, asking for confirmation of task acceptance */ )
{
errors.addConfirmation( confirmation );
}
} |
|