| example.application |
<application name="example">
<library id="xtile" specification-path="/org/mb/tapestry/xtile/xtile.library"/>
</application>
|
| Home.html |
<html jwcid="@Shell" title="XTile example">
<body jwcid="@Body">
Start typing the name of a country in the field below. <br>
The page will connect to the server and ask for possible completions.
<p>
<form name="f">
<table cellspacing="0" cellpadding="0">
<tr>
<td>Country: </td>
<td><input type="text" style="width: 200px" onkeyup="sendValue(this.value)"/></td>
</tr>
<tr>
<td></td>
<td><textarea name="comps" rows="10" style="width: 200px" disabled="true"></textarea></td>
</tr>
</table>
</form>
<span jwcid="@xtile:XTile" listener="ognl:listeners.handleCallback"
sendName="sendValue" receiveName="recvCompletions"/>
<script>
function recvCompletions(arr) {
document.f.comps.value = arr.join("\n");
}
</script>
<span jwcid="@xtile:Timeout"/>
</body>
</html>
|
| Home.java |
public class XTileTest extends BasePage
{
private final static int MAX_COMPLETIONS = 10;
private static Set countries = new LinkedHashSet();
static {
Locale[] locales = Locale.getAvailableLocales();
for (int i = 0; i < locales.length; i++) {
String country = locales[i].getDisplayCountry();
if (country != null)
countries.add(country);
}
}
private String[] findCompletions(String typed)
{
if (typed.equals(""))
return null;
typed = typed.toLowerCase();
List completions = new ArrayList();
for (Iterator it = countries.iterator(); it.hasNext();) {
String country = (String) it.next();
if (country.toLowerCase().startsWith(typed))
completions.add(country);
if (completions.size() == MAX_COMPLETIONS)
break;
}
Collections.sort(completions);
return (String[]) completions.toArray(new String[completions.size()]);
}
public void handleCallback(IRequestCycle cycle)
{
Object[] params = cycle.getServiceParameters();
if (params.length == 0) return;
String typed = params[0].toString();
String[] ret = findCompletions(typed);
cycle.setServiceParameters(ret);
}
}
|