uibinder - GWT 2.5.1: dynamic required field indicator -


what better approach displaying dynamic required field indicator (in case, display '*' next field if empty, hide if user type something, display again if user clears input field) ? indicator called requiredfieldhighlight in code below.

myvalueboxeditordecorator.java

public class myvalueboxeditordecorator<t> extends composite implements haseditorerrors<t>, iseditor<valueboxeditor<t>> {     interface binder extends uibinder<widget, myvalueboxeditordecorator<?>>     {         binder binder = gwt.create(binder.class);     }      @uifield     divelement label;      @uifield     simplepanel contents;      @uifield     divelement requiredfieldhighlight;      @uifield     divelement errorlabel;      private valueboxeditor<t> editor;      private valueboxbase<t> valuebox;      /**      * constructs valueboxeditordecorator.      */     @uiconstructor     public myvalueboxeditordecorator()     {         initwidget(binder.binder.createandbindui(this));     }      public myvalueboxeditordecorator(int dummy)     {         this();          valuebox = (valueboxbase<t>) new textboxtest(requiredfieldhighlight);         this.editor = valuebox.aseditor();           valuebox.addvaluechangehandler(new valuechangehandler<t>()                 {             @override             public void onvaluechange(valuechangeevent<t> event)             {                 myvalueboxeditordecorator.this.onvaluechange();             }                 });          contents.add(valuebox);          myvalueboxeditordecorator.this.onvaluechange();     }      private void onvaluechange()     {         t value = editor.getvalue();          if (value == null)         {             requiredfieldhighlight.getstyle().setdisplay(style.display.inline_block);             return;         }         else         {             requiredfieldhighlight.getstyle().setdisplay(style.display.none);         }     }      public valueboxeditor<t> aseditor()     {         return editor;     }       public void seteditor(valueboxeditor<t> editor)     {         this.editor = editor;     }      @uichild(limit = 1, tagname = "valuebox")     public void setvaluebox(valueboxbase<t> widget)     {         contents.add(widget);         seteditor(widget.aseditor());     }      @override     public void showerrors(list<editorerror> errors)     {         // manages content of errorlabel uifield     } } 

uibinder file:

<ui:uibinder xmlns:ui='urn:ui:com.google.gwt.uibinder'     xmlns:g='urn:import:com.google.gwt.user.client.ui'>      <ui:style src="common.css" />      <g:htmlpanel width="100%">         <div ui:field="label"  class="{style.label}"/>         <g:simplepanel ui:field="contents" styleprimaryname="{style.contents}" />         <div class="{style.errorlabel}" ui:field="errorlabel" />         <div class="{style.errorlabel} {style.requiredfieldhighlight}" ui:field="requiredfieldhighlight">*</div>     </g:htmlpanel> </ui:uibinder> 

the issue approach onvaluechange() not called when screen initialized (before user interacts widget), although need myvalueboxeditordecorator update status of 'requiredfieldhighlight' ! why created textboxtest class. pass reference indicator divelement object , overload settext+setvalue.

textboxtest.java

public class textboxtest extends textbox {     @override     public void settext(string text)     {         super.settext(text);         updaterequiredfieldhighlight(text);     }      private final divelement requiredfieldhighlight;      public textboxtest(divelement requiredfieldhighlight)     {         super();         this.requiredfieldhighlight = requiredfieldhighlight;     }      private void updaterequiredfieldhighlight(string withvalue)     {         if (withvalue != null && !withvalue.isempty())         {             requiredfieldhighlight.getstyle().setdisplay(style.display.none);         }         else         {             requiredfieldhighlight.getstyle().setdisplay(style.display.inline_block);         }     }       @override     public void setvalue(string value, boolean fireevents)     {         super.setvalue(value, fireevents);         updaterequiredfieldhighlight(value);     } } 

i have several problems approach. first, creates dependency specific class of mine (textboxtest), , second, not work because settext() not automagically called gwt when clear contents of text field using gui ! in other words indicator work properly, need both overload settext+setvalue in textboxtest class and have valuechangehandler added myvalueboxeditordecorator object. why ? (and right event / place handle text change ?)

20150629 update: setvalue() called when screen initialized. valuechangehandler not triggered, 'though, due gwt internals (i think due setvalue() provided without fireevents flag calling fireevents overload false fireevent flag).


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -