如何使用ajax显示DOJO Autocompleter值

时间:2012-10-15 11:07:33

标签: java ajax struts2 dojo

我正在尝试使用dojo autocompleter对信息的hashmap进行ajax检索,但下拉菜单上似乎没有显示任何内容。请帮忙

我的JSP代码:

 <sx:head/>
 .......
 <s:url id="companyList" action="AjaxAutoCompleteCompanyPOCAction" />
 <sx:autocompleter name="company" href="%{companyList}"  size="24" loadOnTextChange="true"  preload="false" loadMinimumCount="1" showDownArrow="false" autoComplete="false" searchType="substring" key="rental.company"/>

我的Struts.XML:

  <action name="AjaxAutoCompleteCompanyPOCAction" class="com.kodi.action.jobs.AjaxAutoCompleteCompanyPOCAction" method="retrieveListOfCompany" >
       <result type="json">
           <param name="root">json</param>
       </result>
    </action>

我的行动

 public String retrieveListOfCompany(){
    //if(KodiUtil.isMatch(getCompany())){ // validate special char
        setJson(new HashMap<String, String>()); // create a JSON hashmap
         if(company != null && company.length() > 0) { // check if string is empty
              List<CompanyEntity> companylist = manager.retrieveCompanyName(getCompany());  // retrieve the companies name
              for (CompanyEntity companies : companylist){
                 getJson().put(companies.getCompany_name(),""+companies.getCompany_id());
              }

         }
    return "SUCCESS";

}

截至目前,代码在我的Action类中调用了retrieveListOfCompany(),获取数据但是它没有显示在JSP页面上..请帮忙.. 我收到了这个错误,

No result defined for action com.kodi.action.jobs.AjaxAutoCompleteCompanyPOCAction and result SUCCESS
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:375)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)

但是当我将struts.xml设置为

<result name="SUCCESS" type="json">
           <param name="root">json</param>
       </result>

我得到这个=(

java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.get(Ljava/lang/Object;)Ljava/lang/Object;
    at com.googlecode.jsonplugin.JSONResult.execute(JSONResult.java:157)
    at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:277)
    at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)

我正在使用struts2-dojo-plugin-2.1.8.1.jar

谢谢!

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

我终于发现我的应用程序出现了问题,

我得到的错误是jsonplugin与我的dojo和struts核心不兼容的becoz ..

所以,如果有人遇到同样的问题,只需将你的jar文件降级为更兼容的版本

目前我正在使用

struts2的-JSON-插件-2.2.1

的struts2-道场-插件-2.1.8.1

struts2的核 - 2.2.1.1

希望这有帮助