Mentawai Recipes
Search
Recent Topics
Hottest Topics
Member Listing
Back to home page
Moderation Log
Register
/
Login
Ajax Autocomplete
Forum Index
»
Official Recipes
Author
Message
11/01/2008 15:15:37
Subject:
Ajax Autocomplete
robertwgil
Joined: 11/01/2008 15:09:14
Messages: 5
Offline
Action:
public class TestAction extends BaseAction { public String autoCompleter() { String sourceInput = input.getString("sourceInput"); Map<Integer, String> map = new LinkedHashMap<Integer, String>(); if(sourceInput.startsWith("a")) { map.put(1, "a. Somebody with id 1"); map.put(2, "a. Somebody with id 2"); map.put(3, "a. Somebody with id 3"); } else if(sourceInput.startsWith("b")) { map.put(4, "b. Somebody with id 4"); map.put(5, "b. Somebody with id 5"); map.put(6, "b. Somebody with id 6"); } else { map.put(7, "*. Somebody with id 7"); map.put(8, "*. Somebody with id 8"); map.put(9, "*. Somebody with id 9"); } output.setValue(AjaxConsequence.KEY, map); return SUCCESS; } }
ApplicationManager:
public void loadActions() { action(TestAction.class, "autoCompleter").on(SUCCESS, ajax(new JSONGenericRenderer())); }
Jsp:
<%@ page contentType="text/html; charset=ISO-8859-1" %> <%@ taglib uri="/WEB-INF/lib/mentawai.jar" prefix="mtw"%> <html> <head> <mtw:ajaxConfig loadPrototype="true"/> </head> <body> <legend>AutoComplete</legend> <table> <tr> <td> Example, "a", "b", * </td> <td width="100px"> </td> <td> Key Selected: </td> <td> Value Selected: </td> </tr> <tr> <td> <input type="text" name="sourceInput" id="sourceInput"> <div id="completeHere" class="auto_complete"></div> </td> <td width="100px"></td> <td> <input type="text" name="autoKey"> </td> <td> <input type="text" name="autoValue"></td> </tr> </table> <script type="text/javascript"> function completeText(key, value) { document.getElementById("autoKey").value = key; document.getElementById("autoValue").value = value; } </script> <mtw:ajaxCompleter onSuccess="completeText" source="sourceInput" target="completeHere" url="TestAction.autoCompleter.mtw"/> </fieldset> </body> </html>
on <mtw:ajaxConfig
loadPrototype="true"
/> say that you want to load Prototype 1.6 and scripts necessaries to run autocompleter.
Screenshot:
Forum Index
»
Official Recipes
Go to:
Select a forum
Official Recipes
Community Recipes
Receitas Oficiais
Receitas da Comunidade
Site Docs
Powered by
JForum 2.1.8
©
JForum Team