Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java UiBinder小部件中的自定义属性_Java_Gwt_Uibinder - Fatal编程技术网

Java UiBinder小部件中的自定义属性

Java UiBinder小部件中的自定义属性,java,gwt,uibinder,Java,Gwt,Uibinder,我正在为我的应用程序使用GWT和UiBinder,我正在尝试这样做 但是自定义的占位符属性将不起作用,因为文本框上没有设置占位符方法-我需要: searchBox.getElement().setAttribute(“占位符”、“搜索”) 回到java代码中。有没有关于如何在UiBinder中实现这一点的想法?我想我可以将它转换为一个普通的输入元素,并尝试获取一个引用及其值,但我不想走这条路 使用方法setPlaceholder(字符串占位符)创建扩展TextBox的自定义SearchBox怎

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

但是自定义的
占位符
属性将不起作用,因为
文本框
上没有
设置占位符
方法-我需要:

searchBox.getElement().setAttribute(“占位符”、“搜索”)


回到java代码中。有没有关于如何在UiBinder中实现这一点的想法?我想我可以将它转换为一个普通的输入元素,并尝试获取一个引用及其值,但我不想走这条路

使用方法
setPlaceholder(字符串占位符)
创建扩展
TextBox
的自定义
SearchBox
怎么样

然后在UiBinder中:


在被问及这个问题大约一年后,我需要使用自定义属性(特别是占位符)。因此,我编写了以下自定义
TextField
类,该类扩展了
TextBox
,保留了GWT
TextBox
的所有底层功能,包括处理程序等。希望有人在搜索时偶然发现这一点。:)


Afaik这是不可能的(正如您所说,您需要一个setter方法)。为什么不在调用
initWidget(uiBinder.createAndBindUi(this))
之后,在相应视图类的构造函数中设置属性呢?编辑:或者编写您自己的占位符功能,也可以在旧浏览器上使用。在
initWidget
之后,我现在正在调用
setAttribute
。。。我不想将演示文稿从XML文件中移出……这可能是我在本例中最终要做的事情,但我发现使用基于属性的HTML 5功能越来越困难:(您也不需要将占位符存储为java变量。您可以直接使用DOM值。
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);
  }
}