Expert Spring MVC and Web Flow

(Dana P.) #1
<tr style="border-width: 0px">
<td>telephone: </td><td><input class="inp" type="text" id="telephone" /></td>
</tr>
<tr style="border-width: 0px">
<td> </td><td style="padding-top: 7px"><input type="button" value="Submit"
onclick="updateOwner()"/></td>
</tr>
</table>

Listing B-8.JavaScript Function for Updating Owners

function updateOwner() {
DWRUtil.getValues(currentPerson);
Clinic.storeOwner(findOwners, currentPerson);
}

function findOwners() {
var s = document.getElementById("owner").value;
Clinic.findOwners(showOwners, s);
}

function showOwners(ownerData) {
document.getElementById("vetlist").style.display = "none";
document.getElementById("ownerlist").style.display = "inline";
DWRUtil.removeAllRows("owners");
DWRUtil.addRows(
"owners",
ownerData,
[getFirstName, getLastName, getAddress, getCity, getTelephone, getOwnerEdit ]
);
}

What’s going on here? First off, we need to explain that the value of the JavaScript variable
currentPersonwas initialized to the name/value pairs of the form when the form was popu-
lated. As the submit button calls the updateOwnerfunction, we take advantage of another
DWR utility method; getValues. Its input is any object that contains name-value pairs—
currentPersonin our example. The names are assumed to be the ids of HTML elements,
and the values are altered to reflect the contents of those ids.
Next, we invoke the storeOwner()method of the Clinicservice object, instructing DWR
to call findOwnersimmediately after the update returns and passing the currentPersonobject
holding the name-value pairs from the input fields as the parameter. In the findOwners()func-
tion, we make the call on the Clinic’s findOwners()Java method and lastly pass control to the
showOwners()function, which updates the display. The page, of course, updates just the values
that were changed in the owner table with barely a flicker to look like the one in Figure B-5.

386 APPENDIX B ■AJAX AND DWR

584X_Ch14_AppB_FINAL 1/30/06 12:55 PM Page 386

Free download pdf