GWT 2.1 UiBinder SimplePager 需要位置属性

发布于 2024-10-02 18:16:42 字数 200 浏览 0 评论 0原文

可以为我尝试过 CENTER 的位置属性提供什么

<c:SimplePager ui:field='pager' location='HERE' /> 

,但它不起作用,我在费用示例应用程序中看到它们没有位置属性,而是在 UiBinder 中创建它时设置它。但我不能这样做,因为它是必需的属性。 该怎么办?

What can be provided to the location attribute of a

<c:SimplePager ui:field='pager' location='HERE' /> 

I tryed CENTER, but it didnt work, I see in the expense sample app that they dont have a location attribute but instead set it on the creation of it in the UiBinder. But I cant do that since its a required attribute.
What to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

明明#如月 2024-10-09 18:16:42

您必须提供 SimplePager.TextLocation,可以是 CENTER、LEFT 或 RIGHT。

<c:SimplePager ui:field='pager' location='CENTER'/>

You must provide SimplePager.TextLocation, which can be CENTER, LEFT or RIGHT.

<c:SimplePager ui:field='pager' location='CENTER'/>
三生路 2024-10-09 18:16:42

目前我看到的唯一解决方案是使用 @UiField(provided = true)。不确定这是否有任何帮助,但无论如何请查看下面的小示例。

ui.xml:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<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:style>

    </ui:style>
    <g:HTMLPanel>
        <c:CellList ui:field="list" />
        <c:SimplePager ui:field="pager" />
        <g:Button ui:field="more" text="addMore" />
    </g:HTMLPanel>
</ui:UiBinder>

和小部件:

public class TestView extends Composite {

    private static TestViewUiBinder uiBinder = GWT.create(TestViewUiBinder.class);

    interface TestViewUiBinder extends UiBinder<Widget, TestView> {}

    @UiField(provided = true)
    CellList<String> list;
    @UiField(provided = true)
    SimplePager pager;
    @UiField
    Button more;
    private int counter = 0;
    private ListDataProvider<String> provider;

    public TestView() {
        list = new CellList<String>(new TextCell());
        pager = new SimplePager();
        initWidget(uiBinder.createAndBindUi(this));
        provider = new ListDataProvider<String>(getList());
        provider.addDataDisplay(list);
        pager.setDisplay(list);
        pager.setPageSize(5);
    }

    private LinkedList<String> getList() {
        LinkedList<String> list = new LinkedList<String>();
        list.add("1st");
        list.add("2nd");
        list.add("3rd");
        list.add("4th");
        list.add("5th");
        return list;
    }

    @UiHandler("more")
    void onMoreClick(ClickEvent event) {
        provider.getList().add(++counter + " more");
    }
}

The only solution I see at the moment is working with @UiField(provided = true). Not sure if that is of any help but check out the small example below anyway.

The ui.xml:

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<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:style>

    </ui:style>
    <g:HTMLPanel>
        <c:CellList ui:field="list" />
        <c:SimplePager ui:field="pager" />
        <g:Button ui:field="more" text="addMore" />
    </g:HTMLPanel>
</ui:UiBinder>

and the widget:

public class TestView extends Composite {

    private static TestViewUiBinder uiBinder = GWT.create(TestViewUiBinder.class);

    interface TestViewUiBinder extends UiBinder<Widget, TestView> {}

    @UiField(provided = true)
    CellList<String> list;
    @UiField(provided = true)
    SimplePager pager;
    @UiField
    Button more;
    private int counter = 0;
    private ListDataProvider<String> provider;

    public TestView() {
        list = new CellList<String>(new TextCell());
        pager = new SimplePager();
        initWidget(uiBinder.createAndBindUi(this));
        provider = new ListDataProvider<String>(getList());
        provider.addDataDisplay(list);
        pager.setDisplay(list);
        pager.setPageSize(5);
    }

    private LinkedList<String> getList() {
        LinkedList<String> list = new LinkedList<String>();
        list.add("1st");
        list.add("2nd");
        list.add("3rd");
        list.add("4th");
        list.add("5th");
        return list;
    }

    @UiHandler("more")
    void onMoreClick(ClickEvent event) {
        provider.getList().add(++counter + " more");
    }
}
原来是傀儡 2024-10-09 18:16:42

SimplePager 类无法由 UiBinder 实例化,因为它没有 Location 的 setter 来修复错误。

@UiField(provided=true) 的替代方案允许自动实例化变量,方法是创建一个工厂方法来指示 UiBinder 外部的页面如何实例化以及在需要时设置对象。

下面是工厂方法的示例,它将应用于任何 @UiField SimplePager 类。 @UiField(provided=true) 将处理多个不同的实例化,但对于一个 UiFactory 来说是最简单的,因为您不必关心何时使用变量。

@UiFactory SimplePager createSimplePager() {
    return new SimplePager(TextLocation.CENTER);
}

The SimplePager class can't be instantiated by UiBinder, because it doesn't have a setter for Location to fix the error.

An alternative to @UiField(provided=true), which allows the variable to be instantiated automatically is by creating a factory method to instruct the page outside of UiBinder on how to instantiate and if needed setup the object.

Here's an example of the factory method it will apply to any @UiField SimplePager class. @UiField(provided=true) would handle multiple varying instantiations, but for one UiFactory is the simplest, because you don't have to be concerned with when the variable is used.

@UiFactory SimplePager createSimplePager() {
    return new SimplePager(TextLocation.CENTER);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文