Uma das coisas que mais me demorou para compreender no DWR é o conceito de callback: você cria uma function (obj javascript) que irá tratar o retorno da chamada ajax e passa essa function no método de chamada do framework DWR. Quando a resposta for processada pelo servidor e enviada para o cliente (browser) será executada essa function e sensibilizado o os campos do html (se for o caso).
<br />
Isso mostra como podemos criar páginas htmls puros fazendo toda a chamada através de forms que são processados por servlets (actions, backbeans, whatever...) e o seu retorno ser tratado por javascript, sem fazer uma página com jsp. Acredito que isso facilita o desenvolvimento, tendo em vista que um programador fica responsável por fazer os objetos de negócio no servidor e outro fica responsável por fazer as páginas de forma estática, respeitando apenas a assinatura do método ajax.
This link has been bookmarked by 6 people . It was first bookmarked on 14 Jan 2008, by 张 海涛.
-
07 Nov 08
-
Before diving into the details, let's review the general flow of an Ajax validation request. When the user changes an input field, JavaScript is used to collect and bundle the necessary form input and transmit it to the server. On the server, some validation process is invoked. The results are returned to the browser, where they are interpreted and used to update the browser's DOM to visually display or hide validation messages. The browser's Ajax call is essentially asynchronously submitting a custom form, a JavaScript callback function is used to handle a custom response, and the custom response is used to dynamically update the page.
-
. The JavaScript used to invoke validation had DWR proxy names embedded in the script, which required the JavaScript to be customized each time it was put in use on a new form.
-
Examples of this situation include validating that a user's zip code exists within their state (does 55431 exist in MN?), that a credit card number belongs to the specified card type (does the card number conform to the format of a Visa card?), and that a password confirmation input field matches what the user entered in the password input field. Since only a single input field was submitted for validation at a time, this type of complex validation was not possible.
-
With the service layer to process validation messages in place, we next need to discuss how communication with the server has been revised. In the next section, you will see how DWR is used to expose and invoke the validation front controller.
-
DWR works by dynamically generating JavaScript based on Java classes. Using a servlet and the necessary JavaScript infrastructure, JavaScript calls made in the browser are transparently sent to the server and invoked on the Java class, with the results returned to the browser and available in JavaScript. This is how server-side logic--in this case, Spring Web MVC validation logic--is exposed to the client through Ajax.
-
As described in the DWR annotation documentation, configuring your application to use DWR annotations is a three-step process.
-
First, you must specify the DWR controller servlet in your web.xml file. Second, the fully qualified class name of each class that is to be exposed through DWR needs to be added to a comma-separated list in the web.xml file. Third, each one of these classes needs to be decorated with DWR annotations.
-
RemoteProxy -
Add Sticky NoteBecause the
validateString()method returns aMap, DWR will use a built-inConverterto transparently convert the map into a JavaScript array. As you'll see in the next section, this array will be used to by a callback method to dynamically update the page with validation error messages. -
-
-
03 Jun 08
Frx bogetzAjax Form Validation Using Spring and DWR, Revised
-
14 Jan 08
-
27 Dec 07
-
07 Dec 07
-
04 Dec 07
Public Stiky Notes
Isso mostra como podemos criar páginas htmls puros fazendo toda a chamada através de forms que são processados por servlets (actions, backbeans, whatever...) e o seu retorno ser tratado por javascript, sem fazer uma página com jsp. Acredito que isso facilita o desenvolvimento, tendo em vista que um programador fica responsável por fazer os objetos de negócio no servidor e outro fica responsável por fazer as páginas de forma estática, respeitando apenas a assinatura do método ajax.
Page Comments
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.