|
Struts 1.x does not include in-built AJAX call processing facilities. However, it is easy to include such facilities. This is owing to the plethora of JavaScript frameworks that include AJAX routines, like Prototype, DOJO and Scriptaculous, just to name a few, combined with the ease of using JavaScript with Struts. The transformations of the specification to implementation code vary for the different AJAX framework, but the connection points are usually easy to identify.
We illustrate this with a simple implementation, involving an AJAX action invoke to update a segment, shown below.
EVENT DESCRIPTORS |
id |
event-source |
parameters |
handler |
handler-class |
security |
call-type |
| getOrderDetail |
forms[orderList].elements[details].click |
orderparam |
{getOrderDetail} |
|
|
ajax |
The event source element would be represented in the element descriptor, only the AJAX event is captured above. The segment to be re-rendered must also be demarcated in the segment descriptor, with the link with the AJAX event (event-id).
SEGMENT DESCRIPTORS |
id |
type |
visible |
enable |
value |
base-page-id |
extends |
event-id |
description |
| orderDetail |
div |
|
|
|
|
|
events[getOrderDetail] |
|
The Parameter used is shown below
PARAMETERS DESCRIPTOR |
id |
orderparam |
parent-id |
|
caption |
|
description |
|
value |
|
|
|
PARAMETER DESCRIPTOR |
id |
value |
required |
| orderId |
{orderListForm.selectedId} |
|
One convenient part is s that it is easy to prototype the AJAX operations. For instance, a mock segment (orderDetailData.html) could be used as shown in the code below.
<script type="text/javascript">
function getDetails(){
var url = 'orderDetailData.html';
var pars = 'orderId=ABC';
var myAjax = new Ajax.Updater(
'orderDetail',
url,
{
method: 'get',
parameters: pars,
evalScripts: true
});
}
</script>
.
.
.
<input type="submit" value="Save" onclick="getDetails();" />
The implementation for this would involve the replacement of the mock entries and tag replacements.
<script type="text/javascript">
function getDetails(){
var url = '/getOrderDetail.do';
var pars = 'orderId=${orderListForm.selectedId}';
var myAjax = new Ajax.Updater(
'orderDetail',
url,
{
method: 'get',
parameters: pars,
evalScripts: true
});
}
</script>
.
.
.
<html:submit value="Save" onclick="getDetails();" />
This example illustrate the ease of implementing AJAX call specifications on the Struts 1.x platform.
|