How to bind a label to text in backing class?

北慕城南 提交于 2020-01-06 08:45:27

问题


How can I bind a GWT label to a string property in the backing class for the view?

Login.ui.xml:
Welcome <g:Label text="{textFromJavaBackingClass}" />

class Login {
  String userName;
  String getUserName() { return userName; }
}

How can I bind the value to String userName?


回答1:


Let's say you have a i18n class MyI18n which extends Messages

Just include the following

<ui:with field="i18n" type="MyI18n"/>

Then

Welcome <g:Label text="{i18n.textFromJavaBackingClass}" />

Note : MyI18n is actually not required to extends Messages, this is just the common way to call any no-arg method.

<ui:with field="clazz" type="AnyClass"/>

Welcome <g:Label text="{clazz.anyMehtodWhichDoesNotTakeArgs}" />



回答2:


Declare class in xml

   <ui:with field="myclass" type='package.ClassName' />

In Ui binder write

g:Label text='{myclass.getUsername}'></g:Label>

Here is the reference for future



来源:https://stackoverflow.com/questions/17109363/how-to-bind-a-label-to-text-in-backing-class

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