|
Integration
Some informations about the integration capabilities of the jaev framework
IntroductionThe jaev framework was built to be integrated in different Java bases applications. There are already two example applications. JSF integrationThe integration into a Java Server Faces (JSF) application is pretty simple. The jaev framework provides basic classes in the com.googlecode.jaev.integration.jsf package. The integration implements the javax.faces.validator.Validator interface to provide the infrastructure for e-mail validation. The only thing you have to do is to write a class which extends com.googlecode.jaev.integration.jsf.DefaultEmailAddressValidator. This class has to provide a no argument constructor and pass a from-address. The EmailValidator class in the JSF example shows the complexity of the task. public class EmailValidator extends DefaultEmailAddressValidator
{
private static final Logger LOG = LoggerFactory.getLogger(Log4jInitContextListener.class);
public EmailValidator() throws MailParseException
{
super("mail@niclas-meier.de");
LOG.info("Initialised JSF validator ...");
}
}To use the e-mail validator in the component definition it must be configured in the faces-config.xm: <validator> <description>Validates the e-mail with the jaev framework</description> <validator-id>jaev.email</validator-id> <validator-class>com.googlecode.jaev.examples.jsf.EmailValidator</validator-class> </validator> Now you can use the e-mail validator in the component definitions: <h:inputText id="email" value="#{emailBean.emailAddress}" required="true">
<f:validator validatorId="jaev.email" />
</h:inputText>The JSF integration of the jaev frameworks depends on the Validator facilities of the JSF specification. Tapestry 5 IntegrationThe Tapetry 5 integration of the jaev framework works quite different to the JSF integration. The main reason for lies in the difference of the validation facilities of the Tapestry 5 framework and the JSF specification. To use the jaev framework in a Tapestry 5 application you may use the Tapestry 5 ioc mechanism. First bind an implementation to the Validator and ResultTranslator interfaces. binder.bind(Validator.class, new ServiceBuilder<Validator>()
{
@Override
public Validator buildService(ServiceResources resources)
{
return Validation.basic().fromAddress(
"expample@jaev.googlecode.com").buildFactory()
.getValidator();
}
});
binder.bind(ResultTranslator.class, StandardMappingTransator.class);When you are implementing a Page you may fetch the onValidateForm event to implement the email validation. void onValidateForm()
{
if (this.email != null && !this.email.isEmpty())
{
Result result = this.validatorService.validate(this.email);
if (!Acceptance.SIMPLE.accept(result))
{
this.emailForm.recordError(this.emailField, this.messages
.format(this.resultTranslator.translate(result), result
.getObjects()));
}
}
}
|
Sign in to add a comment