我需要创建一个按钮(因此它与图像的按钮)在gwt用UiBinder,但我不知道如何进行.这是我的ui.xml代码:
<g:PushButton ui:field="myPushButton"/>
在*.java文件中我定义了:
PushButton myPushButton;
如何将图像添加到按钮?我尝试了以下但不起作用:
<g:PushButton ui:field="myPushButton" image="myImage.gif" />
谢谢
似乎Panel不从HasClickHandlers继承而且我无法将clickHandler添加到DivElement.有没有办法将clickHandler添加到DIV?
编辑:我不能使用Label作为我想要点击的DIV包含其他DIV的原因.
除了引用包含一些"CssResource"并使用ClientBundle获取它之外,我在文档中看不到任何内容,但是如何完全覆盖CellTable的tbody和th?
这可能吗?
假设我们有一个使用UiBinder声明的自定义小部件,它需要在其构造函数中包含一些参数.当我在ui.xml中声明它时,我怎样才能提供这些参数?
那是我有一个
CustomWidget(int param1, int param2)
Run Code Online (Sandbox Code Playgroud)
当我将它添加到ui.xml时,我需要能够:
...
xmlns:my="urn:import:...">
<g:Container>
<my:CustomWidget param1="1" param2="arg2"/>
</g:Container>
Run Code Online (Sandbox Code Playgroud) 我可以在UiBinder模板中使用枚举值作为字段值吗?我正在使用GWT 2.4
像这样的东西
<ui:with field="en" type="com.mine.courierApp.shared.PayerType" />
Run Code Online (Sandbox Code Playgroud)
看起来很有希望,在哪
public enum PayerType
{
Sender,
Recipient
}
Run Code Online (Sandbox Code Playgroud)
但我不能参考enum的值en.Sender.
它甚至可能吗?
当使用<g:LayoutPanel>在UiBinder.ui.xml文件,您可以指定<g:layer>标签.其他一些谷歌构建的小部件也有这样的特殊标签 - <g:tab>甚至还有一个子标签<g:header>.
如何为我自己的小部件指定这些?
我正在尝试使用来自ClientBundleUIBInder模板中的背景图像的图像.我以此讨论为指导,但无法使其发挥作用.
在我的Java类中,我有:
public static interface PriceButtonStyles extends ClientBundle
{
String paidIcon();
@ClientBundle.Source("paid_button_53x31.png")
DataResource paid_buttonAsDataResource();
}
@UiField
PriceButtonStyles priceButtonStyle;
Run Code Online (Sandbox Code Playgroud)
然后在相应的模板文件中我引用它:
<ui:style field="priceButtonStyle" type="com.example.client.PriceButton.PriceButtonStyles">
@url paidIconUrl paid_buttonAsDataResource;
.paidIcon {
background: paidIconUrl 0 0 no-repeat;
}
</ui:style>
Run Code Online (Sandbox Code Playgroud)
在这一点上,我的IDE正在以红色显示"paidIconUrl"字符串,表明某些内容不太正确:

事实上,当我尝试运行它时,我得到:
ERROR: Type com.ecample.client.PriceButton.PriceButtonStyles does not extend com.google.gwt.resources.client.CssResource Element <ui:style field='priceButtonStyle' type='com.example.client.PriceButton.PriceButtonStyles'> (:7).
ERROR: Uncaught exception escaped. com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
Run Code Online (Sandbox Code Playgroud)
在谷歌小组的讨论中,有人建议这可能与之相关,<ui:data>而不是<ui:style>,所以我试图让它发挥作用.但似乎你不能paidIcon()在<ui:data>资源中同时包含CSS样式(例如我的方法)和DataResources .我无法找到很多文档<ui:data> …
我正在尝试使用uiBinder设置flextable.我正在使用GWT 2.4,我知道如何做一个flextable,但不是uiBinder.我发现了这个问题:如何在UiBinder中为GUI Web Toolkit添加行添加行?被问到了SO,但没有关于如何做到这一点的例子.
因此,如果我将小部件声明为:
@UiBinder FlexTable flexTable;
Run Code Online (Sandbox Code Playgroud)
如何使用uiBinder初始化一个空行,该行包含两列和一个用@UiConstructor或(provider = true)命名列的标题行?
如果我在MyView.ui.xml UiBinder文件中定义我的CellTable,如下所示:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:c="urn:import:com.google.gwt.user.cellview.client"
ui:generateFormat='com.google.gwt.i18n.rebind.format.PropertiesFormat'
ui:generateKeys='com.google.gwt.i18n.rebind.keygen.MD5KeyGenerator'
ui:generateLocales='default' xmlns:p1="urn:import:com.google.gwt.user.cellview.client">
...
<g:HTMLPanel>
<c:CellTable
addStyleNames='{style.cellTable}'
pageSize='15'
ui:field='cellTable' width="100%">
</c:CellTable>
</g:HTMLPanel>
Run Code Online (Sandbox Code Playgroud)
然后programmaticaly将列添加到CellTable,一切正常.
但是为了减少样板代码,我想在我的UiBinder文件中定义表列.我试过这个:
...
<g:HTMLPanel>
<c:CellTable
addStyleNames='{style.cellTable}'
pageSize='15'
ui:field='cellTable' width="100%">
<c:TextColumn
addStyleNames='{style.titleColumn}'
ui:field="titleColumn"/>
</c:CellTable>
</g:HTMLPanel>
Run Code Online (Sandbox Code Playgroud)
但它会产生以下错误:
[ERROR] [dialective] - 找到意外的子元素Element addStyleNames ='{style.titleColumn}'ui:field ='titleColumn'>(:33)
如何使用UiBinder定义整个CellTable?
我正在使用GWT 2.4与gwt-platform 0.7和gin 1.5.0.
我已经为我的GWT应用程序的动态(实时)翻译构建了一个库.因此,每个小部件都会在LocaleChangeEvent被触发时得到通知,然后让我TranslationDictionary获取要显示的新String.
小部件实际上看起来像这样:
public class LocaleAwareLabel extends Label implements LocaleChangeEventHandler {
TranslationDictionary dictionary;
String translationToken;
public LocaleAwareLabel(TranslationDictionary dictionary, EventBus eventBus, String translationToken) {
this.dictionary = dictionary;
this.translationToken = translationToken;
eventBus.addHandler(LocaleChangeEvent.TYPE, this);
getCurrentTranslationFromDictionary();
}
public void getCurrentTranslationFromDictionary() {
this.setText(dictionary.getTranslation(translationToken));
}
@Override
public void onLocaleChange(LocaleChangeEvent event) {
getCurrentTranslationFromDictionary();
}
}
Run Code Online (Sandbox Code Playgroud)
正如你所看到的:我不能轻易地将这个小部件与UiBinder一起使用,在我注入的时刻EventBus和 TranslationDictionary我的View使用方式@UiField(provided=true)如下:
@UiField(provided=true)
LocaleAwareLabel myLabel;
@Inject
public MyView(TranslationDictionary dictionary, EventBus eventBus) {
widget = uiBinder.createAndBindUi(this);
myLabel = new …Run Code Online (Sandbox Code Playgroud)