my dog learned polymorphism
The moose likes HTML, CSS and JavaScript and the fly likes DWR and HTML snippets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "DWR and HTML snippets" Watch "DWR and HTML snippets" New topic

DWR and HTML snippets

Rusty Enisin
Ranch Hand

Joined: May 26, 2005
Posts: 107
I am about to drop the idea of using DWR. But before I did I wanted to ask.

I would like my Java class to return a dynamically generated HTML snippet, not just data. DWR seems to return back data only. I want HTML structured data. Of course I could do this, but there is no JSP with DWR. I would have to hand code string concatenations right in the Java class. Am I just stuck in my MVC pattern world?

An alternative to returning the HTML snippet would be to hide all the HTML snippets in the requesting page, request data from the server, and then merge the two on the front end. I did not want to do this because it required the user to load the HTML snippets when they might not use them. And the JavaScript to process it this way would be much bigger. And the data I am returning is equivalent to a bean that also contains a collection of beans. Creating the output would look similar to writing Servlets without JSP (i.e. tons of string concatenations). That leaves me back at square one.

At this point it seems like it is better to go with directly using the XMLHttpRequest object myself. Then I can use Struts/Servlets and JSPs to create snippets or otherwise structured data as I wish.

Maybe DWR is not the answer? Am I missing something?

The squeaky wheel gets the grease. Well, that or replaced...
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

The whole point of DWR is to approximate an RPC mechansim to call Java methods using Ajax as a transport mechanism. If you are planning to return HTML snippets generated via JSP, DWR is massive overkill.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: DWR and HTML snippets
It's not a secret anymore!