It's all about the answers!

Ask a question

Web UI - Handling Service request results


Rakesh Kukkamalla (5615) | asked Jul 28 '08, 10:22 a.m.
I have a simple REST service on the server and I am trying to write a simple Web UI to display text returned from the service.

I was able to retrieve the results from the service but what I dont know is how to diplay them onto the page. Can you please tell me how to have a simple text area and display my text onto the page? I guess the logic needs to go inside the "success" function of the request Handler. Can you please provide sample code?

Thanks you.

One answer



permanent link
Adam Archer (83639) | answered Jul 28 '08, 11:43 a.m.
FORUM MODERATOR / JAZZ DEVELOPER
What you need to do is use javascript in the success handler to manipulate the dom and inject your text somewhere. So the answer really depends on the current structure of the dom and the references you have to it.

If all you want to do is put text from the result into the ui, this part is trivial. Once you get a reference to a dom node you want to put it in, you can do one of two things:

a) Create a text node out of it and add it to the dom:

var text = document.createTextNode(myString);
myNode.appendChild(text);

b) Use innerHTML on a node to overwrite the content of the node with your text:

myNode.innerHTML = myString;

Note that with approach (b) you have to be careful to ensure that the text does not contain any tags that will be parsed as html (unless you want them to be). Using innerHTML for text from unknown sources can allow people to maliciously inject javascript or other harmful code. Using text nodes will ensure that the text is translated into a textual representation and no html will be parsed.

As far as getting a reference to a desired domNode, usually what we do is use a dojoAttachPoint from the widget that makes the request. For some examples of this, I would suggest you look at the dashboard viewlet code as they are all very self-contained and easy to follow. You will find them in com.ibm.team.dashboard.viewlets.web/resources/ui/internal. The viewlets in there (*.js) will have corresponding templates (*.html) in the /templates sub-directory. You will see that the templates specify dojoAttachPoints that we reference in our service callback using this.attachPointName.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.