aspose file tools*
The moose likes Struts and the fly likes autocompleter tag...not working out. Please help S2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "autocompleter tag...not working out. Please help S2" Watch "autocompleter tag...not working out. Please help S2" New topic
Author

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

Ashu Jain
Ranch Hand

Joined: Feb 24, 2008
Posts: 73
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 24, 2008
Posts: 73
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Feb 24, 2008
Posts: 73
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

Joined: Sep 29, 2008
Posts: 12617

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.
 
wood burning stoves
 
subject: autocompleter tag...not working out. Please help S2