• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Struts2 mapping query

 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?



 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might have to post the entire example; I've never seen this behavior, so I'd have to try it locally.
 
Ranch Hand
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's *so* much extra, unnecessary work.
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


Thats correct, better we can go for Jquery select tag.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think all is fine with server side... so is the mapping correct?
 
reply
    Bookmark Topic Watch Topic
  • New Topic