Thursday, May 19th, 2005

XHR Server Validation with DWR

Category: Java

Joe Walker, creator of DWR, has put up info on Ajax Validation with DWR.

You can look at demo page, and a view source shows you how easy it is to add the JS:

HTML

Credit Card #: 
  <input id="cardnum" type="text" onchange="checkCardNum()"/>
  <span id="cardnum-error" class="error"></span>

JavaScript

<script type='text/javascript' src='/dwr/dwr/interface/CreditCardValidator.js'></script>
<script type='text/javascript' src='/dwr/dwr/engine.js'></script>
<script type='text/javascript' src='/dwr/dwr/util.js'></script>

function checkCardNum() {
  CreditCardValidator.isValid(replyCardNum, DWRUtil.getValue("cardnum"));
}

Servlet: web.xml

<servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>dwr-invoker</servlet-name>
  <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

Posted by Dion Almaer at 5:32 pm
1 Comment

+++--
3.1 rating from 7 votes

1 Comment »

Comments feed

DWRUtil is what here ? any standard l i b r a r y?

Comment by mahendrakar — March 8, 2006

Leave a comment

You must be logged in to post a comment.