Reference elements in GwtBootstrap3 in code

62 views Asked by At

I'm very new to GWT and GwtBootstrap3 so this might be a dumb question, but how can the elements from my ***.ui.xml file be referenced in the code?

For example, I have a paragraph in my ***.ui.xml file -

    <b.html:Paragraph alignment="LEFT">
        Lorem Ipsum
    </b.html:Paragraph>     

and I want to be able to change the text in my code. Similarly, if I'm creating a List but can't statically provide the list elements in my ***.ui.xml file and need to provide them in my code, based on what choices are available, is there a way to do that?

Any suggestions/comments will be really appreciated.

2

There are 2 answers

0
coderwurst On BEST ANSWER

Rohit, I noticed in your answer you changed your initial paragraph widget to a Label element. For anyone else visiting this question and wanting to work specifically with paragraphs: adding the attribute ui:field="myWidget" to an html Paragraph Element will allow you to perform this task directly

UIBinder

xmlns:b.html="urn:import:org.gwtbootstrap3.client.ui.html"    

<b.html:Paragraph alignment="LEFT" ui:field="myWidget">
    Lorem Ipsum
</b.html:Paragraph>

Java

import org.gwtbootstrap3.client.ui.html.Paragraph;

@UiField public Paragraph myWidget;

myWidget.setText("Dynamic text");
0
Rohit On

Found a way finally after research into GWT UiBinder. I inserted a Label widget in the paragraph and provided an id to my Label using ui:field ='myWidget' and the then referenced it in my ***UIBinder.java using:

@UiField Label myWidget;

and set the text in the constructor using

myWidget.setText("Dynamic text");

This can also be done without using widgets