views:

30

answers:

1

I'm using the json plugin that comes with struts 2 (json-lib-2.1.jar) and trying to follow the website to set it up.

Here's my struts.xml

<struts>
   <package name="example"  extends="json-default">
      <action name="AjaxRetrieveUser" class="actions.view.RetrieveUser">
         <result type="json"/>
      </action>
   </package>
</struts>

but I get this warning: SEVERE: Unable to find parent packages json-default

Is there something else I'm supposed to do?

Edit:

I added this method to my RetrieveUser:

public Map<String,Object> getJsonModel()
{
    return jsonModel;
}

And my struts.xml looks like this:

<struts>
  <package name="example"  extends="json-default">
     <action name="AjaxRetrieveUser" class="actions.view.RetrieveUser">
        <result type="json"/>
        <param name="root">jsonModel</param>
     </action>
  </package>
</struts>

However, I don't think the response is going from the RetrieveUser class to the javascript. I'm using firebug and no request gets sent.

A: 

I believe that net.sf.json-lib is just a toolset you can use in your Java to build up JSON-ready objects, suitable to be returned by actions such as you describe.

Probably, you need to include struts-json-plugin - make sure its version matches your struts version.

I notice also that as written, your action will attempt to return RetrieveUser, serialized. Most implementations I've done/seen specify the root object to be returned, by adding

<param name="root">jsonUser</param>

Under the tag, and define this method in RetrieveUser

public Map<String, Object> getJsonUser()

[This is mentioned in the Sruts2 doc]. Hope that helps.

[edit] I use Map - you could also use the object structures provided by json-lib instead.


Re: Your edit. Probably need to see your calling javascript. And probably I will suggest that you make sure you have both a success and an error handler. Can you debug/log to show that the method is being called in java ? Do your logs show anything ? This is usually some sort of error....

kcostilow
edited question
JPC