Sud*_*han 15 java gwt uibinder
我正在为我的应用程序使用GWT和UiBinder,我正在尝试这样做
<g:TextBox ui:field="searchBox" styleName="{style.searchBox}" placeholder="search" />
但是自定义placeholder属性不起作用,因为没有setPlaceholder方法TextBox- 我需要这样:
searchBox.getElement().setAttribute("placeholder", "search");
回到java代码中.有关如何在UiBinder中执行此操作的任何想法?我想我可以把它改成普通的输入元素并尝试获取一个引用及其值,但我宁愿不去那条路.
Ili*_*lin 14
如何创建随方法SearchBox扩展的自定义?TextBoxsetPlaceholder(String placeholder)
然后在UiBinder:
<custom:SearchBox ui:field="searchBox" styleName="{style.searchBox}" placeholder="search" />
在被问到这个问题大约一年之后,我需要使用自定义属性(特别是占位符).所以我编写了以下自定义TextField类,它扩展TextBox了GWT的所有底层功能,TextBox包括处理程序等.希望有人在他们的搜索中偶然发现这一点.:)
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);
  }
}
| 归档时间: | 
 | 
| 查看次数: | 6830 次 | 
| 最近记录: |