0

I have a HTML widget in my ui.xml which I am using in Uibinder to populate data as given below:

ui.xml ->

 <g:HTML ui:field="operationsDetailTableTemplate" visible="false">
    <table class="{style.LAYOUT_STYLE}" width="100%" border="1">
        <tr>
            <td><img src="images/indent-blue.gif"/></td>
            <td>
                <table class="{style.DEFAULT_STYLE}">
                    <thead>
                           <tr>
                               <th>OperationUuid</th>
                                                    ....
                           </tr>
                     </thead>
                      <tbody>
                            <tr>
                                <td>%s</td>
                                 ...
                             </tr>
                      </tbody>
                  </table>
             </td>
        </tr>
         ....
</g:html>

Uibinder.java--->

 String htmlText = operationsDetailTableTemplate.getHTML()
                   .replaceFirst("%s", toSafeString(operation.getOperationUuid()))
                   ....
 HTML html = new HTML(htmlText);
 operationsDetail.add(html);

The above is done in a for loop for each of the operation retrieved from the database. My question is how I can embed a hyperlink or an anchor tag on one of the cell (eg. operation id ) for each of the operation set retrieved. I also wish to have a listener attached to it.

P.S. - It does not allow me to have a anchor tag in HTML in ui.xml.

1 Answers1

0

You'd better use the tools in the way they've been designed to be used: use ui:field="foo" on the <td> and @UiField Element foo + foo.setInnerHTML(toSafeString(...)) instead of extracting the HTML, modifying it and reinjecting it elsewhere. You could also use a <g:Anchor> and attach an @UiHandler to handle ClickEvents.

Your way of using UiBinder makes me think of SafeHtmlTemplates, or the new UiRenderer aka UiBinder for Cells: https://developers.google.com/web-toolkit/doc/latest/DevGuideUiBinder#Rendering_HTML_for_Cells

Thomas Broyer
  • 64,353
  • 7
  • 91
  • 164
  • the only reason I could not think of using the uibinder in the way u described is, i dont have one parituclar field to be set. If you noticed I am retrieving a bunch of operations from the database and I am using the HTML template to populate them on run-time. So I am not sure how many such operations would exist each with field 'foo'. – dhavalp Jul 04 '12 at 02:36
  • Is there any better way I can do it? – dhavalp Jul 04 '12 at 02:37
  • SafeHtmlTemplates or UiRenderer (2.5), and/or CellList or CellTable. Or make it a Composite widget and create one instance per "operation". – Thomas Broyer Jul 04 '12 at 20:58
  • i am a begineer with gwt.. can u point me to some link or some code snippet as how could i have multiple instances of composite widget using UIbinder. Do i need to create my own implementation of the widget and then import it in the ui.xml? please share ur expertise.. – dhavalp Jul 04 '12 at 22:09