Java Reference
In-Depth Information
Figure 15.12: Viewing a contact's details
<s:link beanclass="stripesbook.action.ContactListActionBean"
event="details"
onclick="return ajaxLink(this, '#contact_details');">
<s:param name="contact" value="${contact}"/>
<img src="${contextPath}/images/info.gif" border="0"/>
</s:link>
|
We're calling the JavaScript
ajaxLink
( ) function with the request URL
and the ID of the page portion to be updated with the response. Can
you guess what the
ajaxLink
( ) function looks like?
function
ajaxLink(link, update) {
$.get(link,
function
(data) {
$(update).html(data);
$(update).show();
});
return false
;
}
This function is easily reusable; it generically submits an Ajax request
to the given link and updates the identified page portion with the frag-
ment received in the response. For the contact details link, we're pass-
ing the contact ID with the
contact
parameter and calling the
details
( )
event
handler
on
ContactListActionBean
,
which
forwards
to
contact_
details.jsp
:
public abstract class
ContactBaseActionBean
extends
BaseActionBean {
private
Contact contact;
public
Contact getContact() {
return
contact;
}
Search WWH ::
Custom Search