jsbridge is an example showing the reuse of Java Script code in a Java application. This allows you to develop your validation logic in one place (client side) and reuse it in the backend service.
See Scripting API for details of implementing calls to the scripting engine.