无法在struts2 jquery json autocompleter标签上获得自动完成功能

时间:2012-10-25 15:51:34

标签: java jquery json autocomplete struts2

我目前正在更改自动填充程序,它可以使用简单的列表来处理json,以便能够链接它们。

我从我的动作中定义了一个json输出(从我的struts.xml中提取):

<action name="listCompanies" class="web.action.SearchAction" method="getCompaniesAction">
<result type="json">
  <param name="root">companies</param>
</result>
</action>

链接到代码(SearchAction的摘录):

   public String getCompaniesAction() throws Exception{
  if (term!=null && term.trim().length()>1) {
    companies=new ArrayList<KeyValuePair>();
    IServiceReferential serviceReferential = (IServiceReferential)getService(IServiceReferential.class);
    List<ICompany> listDaoCompanies =
        serviceReferential.getCompanies(getUserLoginSession(),term);

    for (Iterator<ICompany> it = listDaoCompanies.iterator(); it.hasNext();){
        ICompany company = (ICompany) it.next();
        companies.add(new KeyValuePair(company.getId().toString(), company.getCompanyname()));
    }
  }
  return SUCCESS;
}

听起来很棒:当我问json动作时它会起作用并返回: [{ “键”: “1”, “值”: “器Comp1”},{ “键”: “2”, “值”: “器Comp2”}]

jsp中的autocompleter标记如下所示:

<s:url id="url_companies" action="listCompanies" />
<sj:autocompleter size="1" name="selectCompany" href="%{url_companies}" list="companies" listKey="key" listValue="value" delay="100" loadMinimumCount="2"  onSelectTopics="/autoCompanyChange"/>

它很好地解决了json动作,但文本框从未建议我完成。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您需要从autocompleter

中删除list =“companies”属性
相关问题