*
The moose likes Struts and the fly likes Struts2 mapping query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 mapping query" Watch "Struts2 mapping query" New topic
Author

Struts2 mapping query

Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
This is a mapping related query...

Actually I have all mappings in struts.xml file and everything was going smooth.

I added some json stuff to my code and added a json mapping in struts.xml and I am unable to go to next page,I mean I move between pages on button clicks in my application;

After I added the json mapping, on click of a button a window pops up asking me to save the paricular action class or not instead of moving to next page...why is that so?

Here is my mapping information...
--------------------------------




I get this one...
-------------------------------------------


what could be it? If I remove that json mapping,I dont get this .Anything wrong with the mapping?



David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please stop posting the same question--if somebody knows the answer they'll tell you.

What does the jsonData look like? When I search the web for this type of issue I find a bunch of applet-related stuff.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Thanks David! I felt my explanation was not good for not having received any response for my thread in such a rich forum...

By the by,I never knew it's being studied behind the scenes (Introducing a "Views" column in Javaranch would be a good indication of how thread is faring )

The json data looks(is prepared) like this...



The above Hashmap contains a single value at this point...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You might have to post the entire example; I've never seen this behavior, so I'd have to try it locally.
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

David Newton wrote:You might have to post the entire example; I've never seen this behavior, so I'd have to try it locally.

As David Newton said it does not looks like struts mapping problem.

Pradeep Adibatla


Are you trying to pass json to javascript? Then you can replace by


A.A.Anbarasu
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why would you want to do that (the mapping replacement)? You're not sending back HTML. The "json" result already defaults to something reasonable, and has its own "contentType" parameter.

http://cwiki.apache.org/WW/json-plugin.html
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Yes I am passing json to javascript...

you mean,this should do??



what is "response.html" thr? is it the name of the file which is going to take json values??
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336


I think the above one is incorrect....

I just picked up from an example and wrote "jsonData" as seen in between param tags above...

but I don't know what should exactly come there...

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Pradeep Adibatla wrote:but I don't know what should exactly come there...

Did you read the documentation at the link I posted? It should be the root object you're serializing to JSON and sending to the client.
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

David Newton wrote:Why would you want to do that (the mapping replacement)? You're not sending back HTML. The "json" result already defaults to something reasonable, and has its own "contentType" parameter.

http://cwiki.apache.org/WW/json-plugin.html


That's correct. this line looks like changing the interceptors flow. Also in my last project i did it in the same way as i said, that is "Creating JSON" in action class using json plugin and streaming it to jsp pages.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336

It should be the root object you're serializing to JSON and sending to the client.


I am unable to comprehend this precisely !!!

I want to populate all cities of the country selected,so,I prepared json for all cities based on country selected...

Now what is the root object that is being serialized to JSON and sent to client?? Little amateur but I should know...

--------------------------------------------------------------------------------------------------------------------------------------------------------------


Also in my last project i did it in the same way as i said, that is "Creating JSON" in action class using json plugin and streaming it to jsp pages.



So how did you stream the data to jsp after preparing the data?? By the way I didn't use any interceptors here...

Like I prepared like this in action.I have to select boxes one below the other. Intially I select a country from select box and based on the value I need to populate the cities associated into the second one.So,on selecting a country, I pass the value to action class via an Ajax call...
---------------------------------------------------------------------------------------------------------------------------------------------------------



Now in jsp this is what I did to populate in second select...
-----------------------------



But I think all the problem is with mapping...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I have no idea what object you're populating in your action. I think you're making this more difficult than it actually is.

A non-JSON action would expose properties which are available in the JSP, right? An action exposing JSON data works in the exact same way, but the root specified in the mapping is the *only* data that will be serialized to JSON and returned to the client. So if you had an action property named "cities" that would be your root.
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

I want to populate all cities of the country selected,so,I prepared json for all cities based on country selected...

Then in action class:

in struts2 config file:

In javascript:


I think this will work
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's *so* much extra, unnecessary work.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Thanks for all those patient replies...

I am trying to populate city object(bean) called City...

So if you had an action property named "cities" that would be your root.


I have a hashmap of cities like...






or

and also I don't even have a default1 package as seen...



Since I already have a default package which has struts.xml it's not allowing the same package name.So I changed it to default1...

Even this is an issue I guess...
Anbarasu Aladiyan
Ranch Hand

Joined: Jun 02, 2009
Posts: 182

David Newton wrote:That's *so* much extra, unnecessary work.

Thats correct, better we can go for Jquery select tag.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're missing the point: the JSON plugin does all the stuff you're doing automatically--I'm not talking about the client side. The client side doesn't care how the JSON is created.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
I think all is fine with server side... so is the mapping correct?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts2 mapping query