GWT - What's the shortest way of simply sharing strings and number constants between Java code and UiBinder files?

社会主义新天地 提交于 2020-01-01 12:05:25

问题


Can someone post an example of the shortest way of sharing a (preferably static final) string or number constant between Java code and UiBinder XML, where I can use the constant either in an attribute:

<g:TextArea width="...px"/>

or in a value:

<g:Label>...</g:Label>

I can't seem to find an example of this, only text from a file, which I don't want.


回答1:


static fields (and enum constants) can be used with a simple <ui:import>:

<ui:import field="com.example.Pojo.CONSTANT" />

or

<ui:import field="com.example.Pojo.*" />

and then simply:

<g:Label text="{CONSTANT}" />

or

<g:Label><ui:text from="{CONSTANT}"/></g:Label>

See https://code.google.com/p/google-web-toolkit/source/browse/trunk/user/test/com/google/gwt/uibinder/test/client/WidgetBasedUi.ui.xml#87 for an example.



来源:https://stackoverflow.com/questions/14778419/gwt-whats-the-shortest-way-of-simply-sharing-strings-and-number-constants-bet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!