my dog learned polymorphism*
The moose likes Struts and the fly likes Autocompleter with ajax theme Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Autocompleter with ajax theme" Watch "Autocompleter with ajax theme" New topic
Author

Autocompleter with ajax theme

Chhaya Patil
Greenhorn

Joined: Nov 14, 2008
Posts: 17
Hi,

I have a autocompleter field with AJAX theme to dynamically populate list. But problem is it does not display list data.

here is my code in jsp :

<s:head theme="ajax" />
.
.
.
.
<s:url id="json" value="/categoryAjaxAction.action" />
<s:autocompleter loadOnTextChange="true" loadMinimumCount="1" theme="ajax" name="categoryStr" value="%{category}"
href="%{json}" dataFieldName="categoryStr" id="%{someId}" />

my action code looks like this -

Map<String, String> map = new HashMap<String, String>();
map.put("1", "A");
map.put("2", "B");
this.setCategoryStr(map);
return SUCCESS;

Here is my struts.xml
<action name="categoryAjaxAction" class="com.a.b.c.CategoryAjaxAction" >
<result name="success">/pages/abc.jsp</result>
</action>

Can anybody help me finding what i am missing??? I was able to populate static list very easily with simple theme.

Thanks

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'd try a few things first:

1) <s:head theme="ajax" debug="true"/>
2) href="%{#json}"
3) Make sure action accessible via browser (i.e., run it manually)
4) <result name="success">/pages/abc.jsp</result> contents--is it producing valid JSON?
5) Make sure Ajax request being made/response coming back appropriately (via Firebug or proxy etc.)
Chhaya Patil
Greenhorn

Joined: Nov 14, 2008
Posts: 17
Thanks for replying.

I set the debug=true. and i see the syntax error on page. I do not know why the syntax error is happening.
Does my page have to show the Map data in source?? it does not show any.

for eg something like this?

items: [
{name: '1'},
{name: '2'},
]

Also my ajax action does work, i tried running it manually. actually the ajax action is fired while loading page each time but the list is not populated. Also when user starts
typing the ajax action is not called.

Any suggestions?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

i see the syntax error on page. I do not know why the syntax error is happening

...

Providing some information about the nature of the syntax might be helpful, otherwise we have absolutely nothing to go on. Here's an analogy: my car doesn't start. I do not know why. Any suggestions?

Does my page have to show the Map data in source?? it does not show any.

I'm not sure what that means.

The autocompleter tag expects JSON data. Are you returning JSON data? Did you change the URL reference?

We have no way of knowing what you're doing or what's happening unless you tell us.
Chhaya Patil
Greenhorn

Joined: Nov 14, 2008
Posts: 17
the error just say Syntax error ( DEBUG: [SyntaxError: Syntax error] ) and then shows html source for page. btw, i have multiple rows on page (so multiple autocpmpleters) so i see syntax error and source code.

if i remove the autocompleter then there is no error on page, which means that that's the piece which generates error.

I really do not have any idea what do you mean by


<result name="success">/pages/abc.jsp</result> contents--is it producing valid JSON?

As i am completely new to it.

and about my last reply , i though you are asking me if i see any of the list data in page source. so i said i do not see it.


Thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The autocompleter expects JSON data. If you're not returning JSON data from the action used by the autocompleter tag, it won't work.

1) Are you returning JSON data? The format expected by the tag is detailed in the autocompleter docs--but you must look at the Struts 2.0.11 docs, because after that the documentation describes the Struts 2.1 Ajax tags.

2) Did you change the href attribute used by the autocompleter tag and add the "#" character?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Autocompleter with ajax theme
 
Similar Threads
Problem in struts 2.0 autocompleter tag.
S2: autocompleter - how to populate a list based on user's input?
Autocompleter Struts2 not working for me:: Please help
Autocompleter
autocompleter tag...not working out. Please help S2