UiBinder小部件中的自定义属性

我正在为我的应用程序使用GWT和UiBinder,我正在尝试这样做

但是自定义placeholder属性不起作用,因为TextBox上没有setPlaceholder方法 – 我需要这样:

searchBox.getElement().setAttribute("placeholder", "search");

回到java代码中。 有关如何在UiBinder中执行此操作的任何想法? 我想我可以把它改成普通的输入元素,并尝试获取一个参考及其值,但我宁愿不去那条路。

如何创建使用方法setPlaceholder(String placeholder)扩展TextBox自定义SearchBox

然后在UiBinder:

在被问到大约一年之后,我需要使用自定义属性(占位符,特别是)。 所以我编写了以下自定义TextField类来扩展TextBox ,留下GWT TextBox所有底层function,包括处理程序等。 希望有人在他们的搜索中偶然发现这一点。 🙂

 public class TextField extends TextBox { String placeholder = ""; /** * Creates an empty text box. */ public TextField() {} /** * Gets the current placeholder text for the text box. * * @return the current placeholder text */ public String getPlaceholder() { return placeholder; } /** * Sets the placeholder text displayed in the text box. * * @param placeholder the placeholder text */ public void setPlaceholder(String text) { placeholder = (text != null ? text : ""); getElement().setPropertyString("placeholder", placeholder); } }