You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jiří Chaloupka <ko...@chalu.cz> on 2009/02/18 16:56:23 UTC
ajax autocompleter
Hi,
I tried to use autocompleter on base of tutorial
http://www.benmccann.com/dev-blog/struts-2-ajax-tutorial-dojo-autocompleter-example/,
which do nothing.
My code is:
public class HintAddresses extends ActionSupport{
private String namePart;
private Map<Integer,String> json;
static Logger log = Logger.getLogger(HintAddresses.class);
public String getAddresses(){
try{
log.info("call getAddresses");
setEnableAjax(new Boolean(true));
json = new HashMap<Integer,String>();
...
List<Customers> list = instance.findByPartOfName(namePart);
for(Customers c : list){
json.put(c.getId(), c.getName()+", "+c.getStreet()+"
"+c.getZip()+" "+c.getCity());
}
}
catch(Exception e){
log.error(e.getMessage());
e.printStackTrace();
}
return SUCCESS;
}
...
In struts.xml I have
<package name="ajax" extends="json-default">
<action name="AutocompleteAddress"
class="cz.chalu.addresses.HintAddresses">
<result type="json"><param name="root">json</param></result>
</action>
</package>
in base template:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="/tags/c" prefix="c" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<html>
<head>
<SCRIPT TYPE="text/javascript" SRC="templates/inc/dojo/dojo.js"></SCRIPT>
<title><s:property value="getText('application.title')" /></title>
<link rel="stylesheet" type="text/css" href="templates/inc/styles.css"
media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
...
<tiles:insertAttribute name="body" />
and in body file:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
<table>
<tr>
<td><s:text name="simplesearch.bynameorperson"/></td>
<td>
<s:url id="AddressList" action="AutocompleteAddress"
method="getAddresses" />
<sx:autocompleter name="namePart" href="{%AddressList}" size="24" />
When I try to type text into autocompleted textfield, nothing happens
and address is not called (there is logging message)
I am using Struts 2.1.6, struts2-dojo-plugin-2.1.6.jar and
jsonplugin-0.33.jar are included in lib folder
Where can be problem, what I understand not well?
Thanks
Jiri
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org