You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kyle Adams <ka...@gfs.com> on 2007/04/19 18:32:51 UTC

[S2] JSON Plugin and No Result Defined

I suspect my problem is something obvious, the type that makes committers
fire off "please read the list!" e-mails...

But I've been searching through the list and haven't had any luck. 
Apologies in advance.

I'm using the JSON plugin.  As a sanity check, I tried to get the
JSONExample listed at http://cwiki.apache.org/S2PLUGINS/json-plugin.html up
and running in my (very simple) web app.  I had to make a few modifcations
that should probably be corrected in the Confluence page, but more on that
later.

The end result was that I was able to get the proper JSON response from
JSONExample.  So I copied the <action/> and pointed the new one at my Action
class (also setup the Spring plugin to autowire my service manager to my
action class):

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

    <package name="example" extends="json-default">
        <action name="JSONExample" class="example.JSONExample">
            <result type="json"/>
        </action>
        <action name="item" class="com.gfs.item.webapp.action.ItemAction">
            <result type="json"/>
        </action>
    </package>
</struts>

My action code is supposed to see if an item's ID or description is passed
in and then do the appropriate service call depending on which attribute is
set.  I want to return a JSON array of the item(s) that matched:

public class ItemAction {
    private ItemManager itemManager = null;
    private Long id = null;
    private String description = null;
    private Collection<Item> items = null;

   public String execute() {
        if (id != null) {
            items = new ArrayList<Item>();
            items.add(itemManager.getItemById(id));
        } else if (StringUtils.isNotEmpty(description)){
            items = itemManager.getItemsByDescription(description);
        }
        return Action.SUCCESS;
    }

    ... getter for the items collection, setters for everyone else ...
}

JSONExample still works, but I get this message when I try to hit
item.action:

"No result defined for action com.gfs.item.webapp.action.ItemAction and
result success"

?  I've got my <result/> right in there.  I didn't even modify the result
when I copied-n-pasted from the JSONExample action.  Why doesn't it
recognize the result?

Thanks,
Kyle
-- 
View this message in context: http://www.nabble.com/-S2--JSON-Plugin-and-No-Result-Defined-tf3608118.html#a10081221
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] JSON Plugin and No Result Defined

Posted by Musachy Barroso <mu...@gmail.com>.
The JSON plugin doesn't really know about that :)

musachy

On 4/19/07, Kyle Adams <ka...@gfs.com> wrote:
>
>
> I've fixed the original problem, but I'm not sure why the fix works...
>
> I had to change my action name to title case:
>
> <action name="Item" class="com.gfs.item.webapp.action.ItemAction">
>
> Is the requirement for a title cased action name specific to the JSON
> plugin?  Other Struts 2 examples have their action names in all
> lowercase...
>
> Kyle
> --
> View this message in context:
> http://www.nabble.com/-S2--JSON-Plugin-and-No-Result-Defined-tf3608118.html#a10082721
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

Re: [S2] JSON Plugin and No Result Defined

Posted by Kyle Adams <ka...@gfs.com>.
I've fixed the original problem, but I'm not sure why the fix works...

I had to change my action name to title case:

<action name="Item" class="com.gfs.item.webapp.action.ItemAction">

Is the requirement for a title cased action name specific to the JSON
plugin?  Other Struts 2 examples have their action names in all lowercase...

Kyle
-- 
View this message in context: http://www.nabble.com/-S2--JSON-Plugin-and-No-Result-Defined-tf3608118.html#a10082721
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] JSON Plugin and No Result Defined

Posted by Kyle Adams <ka...@gfs.com>.

Musachy Barroso wrote:
> 
> I've found that the "Config Browser" plugin helps me a lot to debug this
> kind of problems.
> 

I'll have to look into that plugin.  In the meantime, I think I've got it
figured out.  I had Struts' zero config feature enabled in my web.xml:

        <init-param>
            <param-name>actionPackages</param-name>
            <param-value>com.gfs.item.webapp.action</param-value>
        </init-param>

Once I pulled that out, everything started working as expected (i.e., I
could use "item" as the Action name).  I think the problem was a mish-mash
of zero configuration and explicit configuration.  Once things were working,
I re-enabled zero config, went back and annotated my Action class, and
removed the explicit setup in the struts.xml.  Now my struts.xml looks like
this:

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

My action annotations look like this:

@Result(value = "", type = JSONResult.class)
@ParentPackage(value = "json-default")
public class ItemAction {
...
}

And I get JSON results when accessing
http://localhost/itemService/item.action?id=100129.  It's a lovely thing.

Time to play around with the RestfulActionMappers ;-)

Kyle

PS - As a Struts 1 and JSF refugee, I've been very impressed with Struts 2
so far!  Kudos to all the developers.
-- 
View this message in context: http://www.nabble.com/-S2--JSON-Plugin-and-No-Result-Defined-tf3608118.html#a10084044
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2] JSON Plugin and No Result Defined

Posted by Musachy Barroso <mu...@gmail.com>.
Is there any other error in the logs, while the app is loading? Everything
looks fine to me. I've found that the "Config Browser" plugin helps me a lot
to debug this kind of problems.

regards
musachy

On 4/19/07, Kyle Adams <ka...@gfs.com> wrote:
>
>
> I suspect my problem is something obvious, the type that makes committers
> fire off "please read the list!" e-mails...
>
> But I've been searching through the list and haven't had any luck.
> Apologies in advance.
>
> I'm using the JSON plugin.  As a sanity check, I tried to get the
> JSONExample listed at http://cwiki.apache.org/S2PLUGINS/json-plugin.htmlup
> and running in my (very simple) web app.  I had to make a few modifcations
> that should probably be corrected in the Confluence page, but more on that
> later.
>
> The end result was that I was able to get the proper JSON response from
> JSONExample.  So I copied the <action/> and pointed the new one at my
> Action
> class (also setup the Spring plugin to autowire my service manager to my
> action class):
>
> <struts>
>     <constant name="struts.enable.DynamicMethodInvocation" value="false"
> />
>     <constant name="struts.devMode" value="true" />
>     <constant name="struts.objectFactory" value="spring"/>
>
>     <package name="example" extends="json-default">
>         <action name="JSONExample" class="example.JSONExample">
>             <result type="json"/>
>         </action>
>         <action name="item" class="com.gfs.item.webapp.action.ItemAction">
>             <result type="json"/>
>         </action>
>     </package>
> </struts>
>
> My action code is supposed to see if an item's ID or description is passed
> in and then do the appropriate service call depending on which attribute
> is
> set.  I want to return a JSON array of the item(s) that matched:
>
> public class ItemAction {
>     private ItemManager itemManager = null;
>     private Long id = null;
>     private String description = null;
>     private Collection<Item> items = null;
>
>    public String execute() {
>         if (id != null) {
>             items = new ArrayList<Item>();
>             items.add(itemManager.getItemById(id));
>         } else if (StringUtils.isNotEmpty(description)){
>             items = itemManager.getItemsByDescription(description);
>         }
>         return Action.SUCCESS;
>     }
>
>     ... getter for the items collection, setters for everyone else ...
> }
>
> JSONExample still works, but I get this message when I try to hit
> item.action:
>
> "No result defined for action com.gfs.item.webapp.action.ItemAction and
> result success"
>
> ?  I've got my <result/> right in there.  I didn't even modify the result
> when I copied-n-pasted from the JSONExample action.  Why doesn't it
> recognize the result?
>
> Thanks,
> Kyle
> --
> View this message in context:
> http://www.nabble.com/-S2--JSON-Plugin-and-No-Result-Defined-tf3608118.html#a10081221
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

Re: [S2] JSON Plugin and No Result Defined

Posted by Kyle Adams <ka...@gfs.com>.

Kyle Adams wrote:
> 
> I had to make a few modifcations that should probably be corrected in the
> Confluence page, but more on that later.
> 

Just realized that I forgot to mention those modifications:

* Added a "package example;" at the beginning of JSONExample.java
* Added an "import com.googlecode.jsonplugin.annotations.JSON;" to
JSONExample.java
* Changed line 50 to "@JSON(name="newName")"

Kyle
-- 
View this message in context: http://www.nabble.com/-S2--JSON-Plugin-and-No-Result-Defined-tf3608118.html#a10082716
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org