Automatic form validation in eXistdb

Whenever you need forms in your applications you face the problem of validation. Of course there are a lot of JavaScript solutions out there but that still leaves you with the question how to quickly revalidate the data on the server.

As a first step of our redesign of betterFORM we've developed a facility called 'ModelValidator' that does exactly that but without the need to learn XForms first.

Usually when it comes to user input people start with a plain HTML form as it's the easiest and quickest way to get things running. But once that's done you're left with key/value pairs that you have to check for correct datatype and value range in your server-side scripts. It's certainly no fun task to repeatedly read and check single params before moving on to the interesting part of your application.

Now HTML5 has added some datatypes that have improved the situation but neither all browsers implement them all nor does this give you any safety that the values arriving at the server still adhere to those constraints. Further a simple 'novalidate' put onto the form tag by some unfriendly person before submit disables all checks in the browser and the data are send along as they are.

## What is ModelValidator?

'ModelValidator' is a new facility becoming available in eXistdb very soon that improves this situation. It automatically generates a server-side XForms model that reflects the constraints you've put onto your HTML controls.

Once the user submits the form ModelValidator will intercept the request and generate an XForms model that uses the original HTML document as input and will setup all constraints expressed in the HTML for server-side revalidation. Only in case the incoming data conform to the constraints the submission is forwarded to the action url expressed in the HTML form.

In the context of eXistdb you likely want to send the data to some XQuery script. As its tedious to read all the params one by one ModelValidator does more - it will transform the key/value pairs into an XML structure that you can use as input to your XQuery. Now that you can be sure that your data have been validated before reaching your script you can directly work with the XML.

/exist/apps/wiki/blogs/eXist/modelvalidator.png

But ModelValidator can do even more if you are willing to dive into the XForms Model syntax - every time an XForms model is generated for a form it will be stored into the database. When a new request comes in it will check if a model has already been generated and will use it if that's the case. You can now edit the generated model to establish even more rigid constraints that HTML5 does not allow to express.

Last but not least the current prototype does not even need any JavaScript to work - just plain HTML.

## What comes next?

The current prototype does not support all HTML5 datatypes yet and there's still some polishing and testing to do before we can roll it out. Further we have to work out a decent deployment into eXistdb. Hopefully we can publish it with the next version of eXistdb.

ModelValidator is just the first step in our redesign of betterFORM. To provide instant validation once the user has entered a value and to offer more fancy ways of alerting the next iteration will add JavaScript again to speak to the server under the hood. We have decided for modernizing the client-side technologies we're using. Instead of Dojo we'll go for Web Components (likely Polymer) and for the transport we'll exchange DWR (Direct Web Remoting) with Websockets.

## What will happen to 'full' XForms support?

Though we decided to move away from full XForms support (see betterFORM Blog) in betterFORM 6 we made some effort to further support betterFORM 5 as the fully XForms 1.1 compliant alternative. Thus you will be able to use betterFORM 5 and 6 (once it's there) side-by-side in eXistdb. There won't be any change for those that are using betterFORM 5 in their applications. It will just work as before.

http://exist-db.org/exist/apps/homepage/resources/img/book-cover.jpg

The eXistdb book written by Adam Retter and Erik Siegel is now avaible in its final version as ebook or paperback. Go get it.

There's also a in-depth review of the book by Joe Wicentowski.

eXistdb 2.2 Released

eXide212.png

eXide 2.1.2

We've been busy since the summer to test and improve everything, so here it is: eXistdb 2.2 final is out! We think this is a major step forward in many areas. To just highlight a few:

  • New range index: the most important user-configurable index in eXist has been entirely rewritten for scalability and performance, now using Apache Lucene:
    • many times faster on large data sets
    • xpath expressions using multiple filters are optimized into a single index lookup
    • updates and queries scale very well with growing collection size
  • App updates:
    • eXide 2.1.2 is more robust than ever and has many new features
    • monex: a new app for monitoring and profiling eXist-db
  • Extended the security model, now including setUid and setGid, to temporarily escalate permissions inside an application in a safe way
  • Improved crash recovery leading to a more robust recovery procedure and smaller transaction logs
  • Enhancements to the query engine and optimizer leading to improved overall performance, in particular for queries using indexes

For those upgrading from 2.2-RC1 or 2.2-RC2, the main changes in 2.2 final are:

  • improvements to backup/restore: sometimes a restore led to duplicate user accounts or invalid user IDs
  • many improvements to the new range index based on user feedback (thanks!)
  • map support in query engine aligned with XQuery 3.1 specification
  • closed memory leaks

# LTS Edition

Along with the community release, the LTS edition has also been updated to 2.2. As with every major release, the LTS edition uses the same code base as the community edition, but all updates will be limited to carefully checked, production-ready, quality assured bug fixes and enhancements. With the LTS subscription, we make sure customers build their applications on a stable foundation and benefit from the latest improvements without the risk of using a development version.

http://exist-db.org/exist/apps/homepage/resources/img/lts.png

To celebrate the 2.2 release, new customers get the LTS edition with a 50% discount during our autumn special. All money earned through the LTS subscription is directly funding eXistdb development. You thus benefit twice: by building your application on a quality assured version and contributing to the advancement of eXistdb.

Another great video tutorial by Loren Cahlander to help you set up basic authentication in your eXistdb app.

You can also check out his

source code

for the app on github.

Loren Cahlander created a nice introduction presentation on the HTML templating module, which has been part of eXistdb since 2.0. He demonstrates each templating annotation with a simple demo, so if you ever wondered how those generated templating instructions in your eXist app work together, watching the video is recommended: