Muthu
Muthu

Reputation: 1550

Struts2 jquery autocompleter with JSON

I'm using atocompleter in my form with json. This is the part of my struts.xml

   <package name="default" extends="struts-default,json-default">

    <action name="jsonSample" class="com.jaisar.jsep.product.web.action.DatabaseJSON" method="getDatabaseJSONData" >
         <result type="json"/>
    </action>
</package>

My jsp page is :

<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sj" uri="/struts2-jquery-tags"%>

<s:url id="remoteurl" action="jsonSample.action"/>
    <sj:select
    href="%{remoteurl}"
    id="echo"
    name="echo"
    list="languageList"
    emptyOption="true"
    headerKey="-1"
    headerValue="Please Select a Language"/>

Action class method is :

public class DatabaseJSON  extends ActionSupport {
    private List<String> languageList;
public String getDatabaseJSONData()  {
        languageList = new ArrayList<String>();
        languageList.add("Java");
        languageList.add("PHP");
        languageList.add("C#");
        return SUCCESS;
    }
// Setters and getters for languageList .. 
}

But the page doesn't load with the autocompleter. Page shows simply a select box... Any solutions? Plz ... I refered a lot , but i couln't find the silution...

I referred the site http://code.google.com/p/struts2-jquery/wiki/SelectTag#Receive_Entrys_from_a_simple_String_List

Thanks in advance...

Upvotes: 1

Views: 1600

Answers (2)

nmc
nmc

Reputation: 8696

You didn't specify the result name in your struts.xml. Try: <result name="success" type="json">

Upvotes: 0

doctrey
doctrey

Reputation: 1227

I would try putting dataType='json' attribute in the sj:select tag.

Upvotes: 1

Related Questions