GWT UiBinder 有什么方法可以拥有动态的小部件列表吗?

发布于 2024-09-07 02:44:18 字数 111 浏览 2 评论 0原文

Foo 有一个变量 List

Class Foo has a variable List<Button> bar, how can I render each of the buttons using UiBinder? Is it even possible?

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

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

发布评论

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

评论(1

玉环 2024-09-14 02:44:18

UiBinder 是一个用于以声明方式布局小部件的 XML 模板,并且不是渲染器。因此,UiBinder XML 中不能有条件、循环和其他逻辑结构。

相反,您可以做的是在 UiBinder 中设置一个面板,作为您希望所有按钮所在位置的占位符。在您的 Java 类中有对此面板的 ui:field 引用。循环遍历按钮列表并使用字段句柄在 java 代码中将按钮添加到面板。

另一种方法是定义一个组合并将其添加到 UiBinder 中,然后让组合自行渲染按钮。只是取决于什么最适合您的设计。

UiBinder is a XML template for declaratively laying out widgets and is not a renderer. Hence you cannot have conditionals, loops and other logical constructs within the UiBinder XML.

What you can instead do is have a Panel in the UiBinder as mere placeholder for where you would like all your buttons to go. Have a ui:field reference to this panel in your Java class. Loop through the button list and add buttons to the panel in java code, using the field handle.

Other approach would be to define a composite and add the composite in the UiBinder, and let the composite do the rendering of the buttons by itself. Just depends on what is best suitable for your design.

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