Custom XValidationFactory class The custom
XValidationFactory
[0]
class is extended in this library which allows three
custom
XBaseValidator
[0]
to be added to your applications.
These are the FunctionValidation, NumberValidation
and IntegerValidation classes. This customer validation factory can be included
in your project by setting the
ValidationFactory property in the startup
properties file as shown in
An example of the validations file referred to by the
Validations property is shown in
This file declares a validation for each of the custom
validations being handled by the custom
XValidationFactory. The type attribute is
checked by the factory in order to find out the type
of validation to be created. If it doesn't know the
type then the construction of the validation is passed
over to the super class. Now a page can be declared which makes use of
these validations. A sample page is shown in
The page contains three inputs for each of the
custom validations. The button calls the
checkValidations
[0]
function of the page and if there are any exceptions
they can be seen in the console. The
checkChars
function is defined in the
TestPage
class as shown in
The sample checkChars function
Of course this is just a frivolous implementation of
the FunctionValidation class but you can see how
versatile it can be in XUI applications
ValidationFactory=net.xoetrope.goodies.validation.ValidationFactory
Validations=validations.xml
StartPackage=net.xoetrope.goodies.validation.test
StartClass=testpage
<Validations>
<validation name="numberValidation" type="number" msg="Input must be a
valid number"/>
<validation name="intValidation" type="integer" msg="Input must be a valid
integer"/>
<validation name="funcValidation" type="function" msg="Input must contain
the letter 'a'"/>
</Validations>
<XPage class="net.xoetrope.goodies.validation.test.TestPage">
<components>
<Label x="10" y="10" w="100" h="20" content="Number input:"/>
<Edit x="110" y="10" w="100" h="20" name="numberEdit"/>
<Label x="10" y="30" w="100" h="20" content="Integer input:"/>
<Edit x="110" y="30" w="100" h="20" name="intEdit"/>
<Label x="10" y="50" w="100" h="20" content="Function input:"/>
<Edit x="110" y="50" w="100" h="20" name="funcEdit"/>
<Button x="10" y="100" w="200" h="20" content="Validate"
name="validateBtn"/>
</components>
<Events>
<Event method="checkValidations" target="validateBtn"
type="ActionHandler"/>
</Events>
<Validations>
<Validation rule="numberValidation" target="numberEdit"/>
<Validation rule="intValidation" target="intEdit"/>
<Validation rule="funcValidation" target="funcEdit"
method="checkChars"/>
</Validations>
</XPage>
package net.xoetrope.goodies.validation.test;
import net.xoetrope.xui.XPage;
import net.xoetrope.swing.*;
import net.xoetrope.xui.validation.XBaseValidator;
public class TestPage extends XPage
{
public Integer checkChars()
{
XEdit testEdit = ( XEdit )findComponent( "funcEdit" );
if ( testEdit.getText().indexOf ( "a" ) < 0 )
return new Integer( XBaseValidator.LEVEL_ERROR );
else
return new Integer( XBaseValidator.LEVEL_IGNORE );
}
}