*
The moose likes Struts and the fly likes Struts 2 + Json - Autocompleate example not finding Json Action. 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 "Struts 2 + Json - Autocompleate example not finding Json Action." Watch "Struts 2 + Json - Autocompleate example not finding Json Action." New topic
Author

Struts 2 + Json - Autocompleate example not finding Json Action.

daniel mario munoz
Greenhorn

Joined: Apr 02, 2009
Posts: 7
Hello.

Im faily new to Ajax - Struts2 and Json.

Im following this example:

http://www.benmccann.com/dev-blog/struts-2-ajax-tutorial-dojo-autocompleter-example/

I have done some minor modifications, but still cant get it to work.

This is my struts.xml

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />

<include file="auto.xml"/>

<!-- Add packages here -->

</struts>


This is auto.xml

<struts>

<package name="hello" extends="struts-default">

<action name="Hello" class="org.karinasoft.actions.Hello">
<result>/index.jsp</result>
</action>

<action name="ListingAction" class="org.karinasoft.actions.ListingAction">
<result>/Listing.jsp</result>
</action>

<action name="DetailsAction" class="org.karinasoft.actions.DetailsAction">
<result>/Details.jsp</result>
</action>

</package>

<package name="example" extends="json-default">

<action name="AutoComplete" class="org.karinasoft.actions.AutoComplete">
<result type="json"><param name="root">json</param></result>
</action>

</package>
</struts>


This is part of index.jsp



<head>
<sx:head debug="true"/>
</head>
<body>

<s:property value="message" />
<s:url id="hello" action="Hello" />
<s:a href="%{hello}"> Say Hello !!! </s:a>


<s:url id="cityList" action="AutoComplete" method="getCities" />
<sx:autocompleter name="city" href="%{cityList}" size="24" loadOnTextChange="true" loadMinimumCount="3" autoComplete="true"/>

<sx:autocompleter name="test" list="{'apple','banana','grape','pear'}" autoComplete="true"/> ...



Hello Action runs just fine (but its not ajax!). However when I try to run make the first autocompleter I get this error message

WARNING: Could not find action or result
There is no Action mapped for namespace / and action name AutoComplete!getCities. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:177)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:47)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:458)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)


This is breaking my head! The other actions are findable, they work just fine. I dont know why this action AutoComplete is not been found!

Any help will be greatly appreciated.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Because it's in a different namespace, which is more or less what the error tells you!
daniel mario munoz
Greenhorn

Joined: Apr 02, 2009
Posts: 7
OK, I did the following change:

in auto.xml (added namespace to the package):
<package name="example" namespace="/json" extends="json-default">

<action name="AutoComplete" class="org.karinasoft.actions.AutoComplete">
<result type="json"><param name="root">json</param></result>
</action>

</package>

in index.jsp, added namespace to the url:


<s:url id="cityList" action="AutoComplete" namespace="/json" method="getCities" />
<sx:autocompleter name="city" href="%{cityList}" size="24" loadOnTextChange="true" loadMinimumCount="3" autoComplete="true"/


And it is still showing me the error. Did I did it wrong?

daniel mario munoz
Greenhorn

Joined: Apr 02, 2009
Posts: 7
Update:

I took everything back to the way I had it:

auto.xml:

<package name="example" extends="json-default">

<action name="AutoComplete" class="org.karinasoft.actions.AutoComplete">
<result type="json"><param name="root">json</param></result>
</action>

</package>


index.jsp:

<s:url id="cityList" action="AutoComplete" method="getCities" />
<sx:autocompleter name="city" href="%{cityList}" size="24" loadOnTextChange="true" loadMinimumCount="3" autoComplete="true"/>


When I open index.jsp and see the code I see the following:

<input dojoType="struts:ComboBox" dataUrl="/autoCompleate/AutoComplete!getCities.action" id="city" autoComplete="true" name="city" size="24" keyName="cityKey" loadOnType="true" loadMinimum="3" visibleDownArrow="true" />
<script language="JavaScript" type="text/javascript">djConfig.searchIds.push("city");</script>


If I copy AutoComplete!getCities.action and put it on the browser, and try to access the Action that way, I get the error message.

If I remove the !getCities then I get null, but I dont see in the console that the action is been called (It should print "Im here")


===

If I keep the namespace, then before the AutoComplate it places the namespace, which Im not sure I want.
daniel mario munoz
Greenhorn

Joined: Apr 02, 2009
Posts: 7
I solved the problem, but not the way I was expecting.

I managed to change the index.jsp autocompleter to:

<s:url id="cityList" action="AutoComplete" />
<sx:autocompleter name="city" href="%{cityList}" size="24" loadOnTextChange="true" loadMinimumCount="3" autoComplete="true"/>

now the call in the action is not been done on the method getCities but on the execute.

At least is working!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Oh, I missed that both packages were in the same namespace--rather than use "quote" tags try using "code" tags; it's much nicer.

Maybe try using the config browser to see what Struts thinks your config is. Make sure devMode is turned on and turn up the logging levels for S2 and XWork and see if anything shows up in the logs. Make sure you haven't turned off dynamic method invocation (I *think* it's enabled by default?)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 + Json - Autocompleate example not finding Json Action.
 
Similar Threads
S2: autocompleter - how to populate a list based on user's input?
Autocompleter Struts2 not working for me:: Please help
autocompleter tag...not working out. Please help S2
Problem in struts 2.0 autocompleter tag.
struts2 jquery autocompleter