Re: "`javascript' is not supported as a JSP scripting language."
Mattias Jiderhamn <[email protected]> Sat, 13 May 2006 11:59:25 +0200
| Newsgroups | gmane.text.xml.resin.user |
|---|---|
| Message-ID | <[email protected]> |
At 2006-05-11 10:15, JavaJosh wrote: >Mattias Jiderhamn wrote: >>JavaJosh wrote: >>>This is changing with the rise of 'AJAX' websites. ... My goal is >>>to execute the same form validation code on the client and on the server. >>The point with AJAX is that you call the server code (Java) from >>the client side, rather than using the client side code >>(JavaScript) on the server. > >Consider a hypothetical application that consists purely of a set of >URLs, each of which which take an XML request and return something. >These endpoints should not trust that the caller is correctly >sending those XML requests, and therefore each requires validation >checking. It is valuable to tell the client that an error is being >committed as soon as possible, so we move that logic closer to the client. Assume you mean better performance/smoother user experience. >Currently this consists of writing validation code in two languages >(or 3 or 4 or 5 if you consider XML Schema or DTDs or custom >validation markup to be languages) each of which must be >independently maintained. Yes, that would be the cost of performance/smooth user experience. >It would be valuable to use the same code insofar as possible in >both places. In a perfect world that code would be in Java, but we >must make due for the least common denominator: JavaScript. Since you will want to process the data on the server too, in many cases pure validation is not enough, so you would need to duplicate the code anyway. (Example: you do not only want to check that the input is a date, you want to put it in a java.util.Date variable and actually perform some data processing). And as stated before: Even if you wanted to use JavaScript on the server side, I don't think coding the JSP using JavaScript is the solution. You'd need a more or less fullblown JavaScript interpreter (such as Rhino) to use outside the JSP. For Caucho to provide a JavaScript interpreter, rather than just JavaScript JSP support, might be interresting in this regard. In our case we have built a combination of JavaScripts and custom tags tags, that lets us do the trivial validation (type check etc) and AJAX server side validation very easily and reusable. On the server side there is a Java counterpart. This code has been in place for years, and in our day to day development we seldom need to think about the distinction between Java and JavaScript.