A component providing the required JavaScript to pass some information to the server and receive its response without reloading the page (Ajax)
Warning:
The
XTileService
that this component uses does NOT activate any page - it simply calls the specified
listener. This means that pageBeginRender() methods will not get called and that
cycle.getPage() will return null.
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| listener | IActionListener | no |
The listener that will be invoked when the Javascript function with the
given name is invoked. Any parameters passed to the send function will
be available from cycle.getListenerParameters(). In addition, the
listener can perform cycle.setListenerParameters() to pass an array of
strings to the JavaScript receive function. If this parameter is not provided,
Tapestry will attempt to find a listener with the capitalized id of the
component, prefixed by "do". For example, jwcid="clear@XTile" would expect
a listener called doClear().
|
|
| sendName | String | yes | The name of the JavaScript function that the script will define to allow the application to send information to the server. | |
| receiveName | String | yes | The name of the JavaScript function that the script will call to allow the application to receive information from the server some time after the send function has been invoked. | |
| errorName | String | no | The name of the JavaScript function that the script will call to indicate that an error has occurred while sending the information to the server. | |
| disableCaching | boolean | no | false | Some browsers cache repeated requests that have identical URLs. Pass 'true' to this parameter to disable caching by making the URLs unique. |
Body: removed
Informal parameters: allowed
Reserved parameters: none
The XTile example has portions implemented in the HTML and a listener method in the page class. They are broken down as follows:
XTileExample.html
<html>
<head>
<title>XTile Example</title>
</head>
<body>
<span jwcid="@contrib:XTile" listener="ognl:listeners.handleListRequest"
sendName="sendPrefix" receiveName="recvList"/>
<form action="Results.html" method="post">
<input type="text" onkeyup="sendPrefix(this.value)"/>
<br/>
<textarea name="listing" rows="5"></textarea>
</form>
<script>
function recvList(arr) {
document.f.listing.value = arr.join("\n");
}
</script>
</body>
</html>
Then in your page class you just need to add the appropriate method.
XTileExample.java
.
.
.
public void handleListRequest(IRequestCycle cycle) {
Object[] params = cycle.getListenerParameters();
if (params.length == 0) return;
String typed = params[0].toString();
String[] ret = findCompletions(typed);
cycle.setListenerParameters(ret);
}
.
.
.