This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts 2 + Updating target element with content returned from url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 2 + Updating target element with content returned from url" Watch "Struts 2 + Updating target element with content returned from url" New topic
Author

Struts 2 + Updating target element with content returned from url

Sunil Anna
Greenhorn

Joined: Apr 08, 2009
Posts: 7
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?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What are you expecting to appear in the target div?

How is the Ajax action creating its output?
Sunil Anna
Greenhorn

Joined: Apr 08, 2009
Posts: 7

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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Apr 08, 2009
Posts: 7
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts 2 + Updating target element with content returned from url
 
Similar Threads
Issues Using jQuery and Ajax to Facilitate Long-Running Processes
use javascript variable as query string in <s:url action
jQuery AJAX display issue
problem when integrating jspell with tinyMCE editor
Unable to display the Applet in jsp display tomcat