15

アプリにGWTとUiBinderを使用していますが、これをやろうとしています

<g:TextBox ui:field="searchBox" styleName="{style.searchBox}" placeholder="search" />

ただし、メソッドplaceholderがないため、カスタム属性は機能しません。これが必要です。setPlaceholderTextBox

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

Javaコードに戻ります。UiBinder 自体でこれを行う方法についてのアイデアはありますか? 通常の入力要素に変更して、参照とその値を取得しようとすることもできると思いますが、その道をたどりたくありません。

4

2 に答える 2

14

メソッドSearchBoxで拡張するカスタムを作成するのはどうですか?TextBoxsetPlaceholder(String placeholder)

次に、UiBinderで:

<custom:SearchBox ui:field="searchBox" styleName="{style.searchBox}" placeholder="search" />

于 2010-10-15T10:11:49.183 に答える
8

これが尋ねられてから約1年後、カスタム属性(具体的にはプレースホルダー)を使用する必要がありました。そこで、ハンドラーなどを含むGWTの基本的な機能をすべてそのままにして、TextField拡張する次のカスタムクラスを作成しました。誰かが検索でこれに遭遇することを願っています。:)TextBoxTextBox

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);
  }
}
于 2011-10-14T15:06:24.250 に答える