• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2 + Updating target element with content returned from url

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm facing an issue while updating an sx:div element with content returned from a url.
Here is my JSP

DrawSparklineSubmit action points to process() method of DrawSparkLinesAction.java

In this process() method I'm updating the div element by invoking

But that's not working. The div element is not getting updated with any data. Am I missing sth here?
 
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
What are you expecting to appear in the target div?

How is the Ajax action creating its output?
 
Sunil Anna
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks David,

I'm trying to send an html text back to browser. It's an <img ... tag with some attributes set (It'd appear as it is on browser, and it's not for showing an image).
On Submit button press I'm invoking process() method that tries to set the contents of sx:div tag

by invoking setSparklineImageCode()

I can not exactly return a string from this method (as struts would try to interpret it as an action result). Then, how should I update this div tag?
Please pardon my ignorance I'm new to Struts and AJAX.
 
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 have to produce output somehow, like via a JSP or something.

So the process() method might return SUCCESS, and the JSP would consist of the image tag:(Or something similar, anyway.)

Things like this are really easy to test: just go to the URL of the Ajax action and see if it produces the output you expect. This one wouldn't create any output, because there's no way for it to.
 
Sunil Anna
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you David,

It seems the only way to update UI components through AJAX in Struts 2 is to have a JSP. That would replace the contents of the UI component. I had tried this approach, though I don't remember it worked. But this seems a lousy way to me as in my case I'd have to create a JSP for every div component update.

Anyway Thanks for your help David
 
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 don't *have* to create a JSP, you could write directly to the response, but in general that's a Bad Idea.

If you're creating HTML, use the mechanisms JEE provides to do so. Generating HTML in servlets is almost never something to start doing.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic