首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UiBinder变量

UiBinder变量
EN

Stack Overflow用户
提问于 2014-03-31 13:36:37
回答 1查看 735关注 0票数 0

我是与UiBinder的重量。我正在使用折叠uibinder (引导库)。我有以下代码:

代码语言:javascript
复制
<b:Collapse b:id="toggle1" existTrigger="true" ui:field="toggle1">
     <b:FluidRow>
           <b:Column size="12">
                <b:Alert close="false" animation="true" heading="Cabecera">
                    Text
                </b:Alert>
               </b:Column>
     </b:FluidRow>
 </b:Collapse>

我的问题是在创建b:id="toggle1“时需要更改它。我需要使用变量。有人能解释我怎么做吗?我在网上看过,但没有找到好的解释。

非常感谢您的建议。

EN

回答 1

Stack Overflow用户

发布于 2014-04-02 14:42:51

调用createAndBindUi()后,在JAVA中设置ID。

代码语言:javascript
复制
collapseWidget.getElement().setId("toggle2");

应采取以下步骤:

  • 在您的gwt.xml中添加下面的条目
  • debugIdui:field一起使用,如ui.xml中所示
  • 现在你可以拿到身份证了 myCheckBox.getElement().getId();
  • 所有Ids都是使用默认前缀gwt-debug-生成的,如下所示。如果你愿意的话,你可以把它移除。 gwt-调试-myCheckBox
  • 使用任何一个getElement().setId()ensureDebugId()。它们之间的区别是用gwt-debug-作为前缀。ensureDebugId()使用前缀。

示例代码:(动态设置cancelButton的ID )

代码语言:javascript
复制
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Widget;

public class MyDialogbox extends DialogBox {

    private static MyUiBinder myUIBinder = GWT.create(MyUiBinder.class);

    @UiTemplate("MyDialogbox.ui.xml")
    interface MyUiBinder extends UiBinder<Widget, MyDialogbox> {
    }

    public MyDialogbox() {
        setWidget(myUIBinder.createAndBindUi(this));
        System.out.println(cancelButton.getElement().getId());
        cancelButton.getElement().setId("cancel");
    }

    @UiField
    Button cancelButton;

    @UiHandler("cancelButton")
    void doOpenDialogBox(ClickEvent event) {
        hide();
    }

}

MyDialogbox.ui.xml

代码语言:javascript
复制
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
    xmlns:g='urn:import:com.google.gwt.user.client.ui'>

    <g:DialogBox autoHide="true" modal="false">
        <g:caption>
            <b>Caption text</b>
        </g:caption>
        <g:HTMLPanel>
            Body text
            <g:Button ui:field='cancelButton' debugId='cancelButton'>Cancel</g:Button>
            <g:Button ui:field='okButton' debugId='okButton'>Okay</g:Button>
        </g:HTMLPanel>
    </g:DialogBox>
</ui:UiBinder> 
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22763042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档