私は現在、単純なリストで動作していた多くのオートコンプリータを 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アクションに尋ねると、それは動作し、戻ります: [{"key":"1","value":"Comp1"},{"key":"2","value":" 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アクションをうまく起動しますが、テキストボックスは私に完了を提案しません。
ありがとうございます。