Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

autocompleter tag...not working out. Please help S2

 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to struts . Please help me in implementing autocompleter tag in textbox.

My java action is ::

public class HelloWorld extends ExampleSupport {

private Map<String,String> testingMap;
private List<String> testingMapKeys;

public String execute() throws Exception {
testingMap = new HashMap<String,String>();
testingMapKeys= new ArrayList<String>();

testingMap.put("TREE","DEL");
testingMap.put("HELLO","MUM");

testingMapKeys.add("TREDD");
testingMapKeys.add("TREND");

return SUCCESS;
}

public Map<String,String> getTestingMap() {
return testingMap;
}

public List<String> getTestingMapKeys() {

return testingMapKeys;
}


}


My Jsp is ::

...
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sx" uri="/struts-dojo-tags" %>
...
<head>
<title><s:text name="HelloWorld.message"/></title>
<sx:head debug="true"/>
</head>

...
<body>
<s:url id="cityTest" action="HelloWorld" />
<sx:autocompleter name="origin" href="%{cityTest}" showDownArrow="false" autoComplete="false" dataFieldName="testingMap" />
...

My Struts .xml

<package name="example" namespace="/example" extends="json-default">
<action name="HelloWorld" class="example.HelloWorld">
<result type="json">/example/HelloWorld.jsp</result>
</action>
.....
</package>

Please tell me where i am wrong. I am unable to get back values of testingMap in Json format in my Jsp. At first i am unable to get to my Jsp page. Please help me with theme ="ajax"

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags. Unformatted code/config/etc. is difficult to read. You can edit your post to include them using the button or re-post the question with proper formatting.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The action used to populate the autocomplete should return JSON, not JSP.

The showcase has an autocompleter example.

Note that the Dojo tags have been deprecated as of Struts 2.1.
 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I was using this in my struts xml file

<action name="HelloWorld" class="example.HelloWorld">
<result>/example/HelloWorld.jsp</result>
</action>

Purpose - Result of the action redirected to HelloWorld.jsp.

Now in HelloWorld.jsp, I require a textbox with autocompleter functionality. I believe for that we require json String

I believe this can be done with


<action name="HelloWorld" class="example.HelloWorld">
<result type="json"><param name="root"></param></result>
</action>
But this way i can not specify which the next jsp. How to do that.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't--the action method/result that returns the JSON won't be the same as the one you're using for a JSP.

Normally the JSON/Ajax actions/results are separate from actions/results that return JSP. In other words, you'd have either a completely separate action/action method returning the JSON.
 
Ashu Jain
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will this work in same workspace or i should have action/result JSP under namespace that extends "struts-default"

<package name="example" namespace="/example" extends="json-default">
<action name="HelloWorld" class="example.HelloWorld">
<result type="json"><param name="root">testingMap</param></result>
</action>

<action name="HelloWorld" class="example.HelloWorld">
<result>/example/HelloWorld.jsp</result>
</action>


Please help and guide.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags. Unformatted code/config/etc. is difficult to read. You can edit your post to include them using the button or re-post the question with proper formatting.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic