Custom attributes in UiBinder widgets

后端 未结 2 1890
遥遥无期
遥遥无期 2021-01-01 21:08

I\'m using GWT and UiBinder for my app, and I\'m trying to do this

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 21:23

    About a year after this was asked, I had a need to use custom attributes (placeholder, specifically). So I wrote the following custom TextField class that extends TextBox, leaving in tact all of the underlying functionality of a GWT TextBox including handlers and such. Hope someone stumbles upon this in their searches. :)

    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);
      }
    }
    

提交回复
热议问题