gwt - Add id to field with ui:field declaration -


i'm trying declare these elements in uibinder xml:

<label for="lastname">last name:</label> <input type="text" id="lastname" ui:field="lastnamefield" maxlength="150" /> 

simply put, label associated text input.

when try compile, however, error:

[error] cannot declare id="lastname" , ui:field="lastnamefield" on same element element (:23)

this seems idiotic restriction, since ui:field doesn't generate id. solution i've found far assign id in java code this:

@uielement inputelement lastnamefield; ... lastnamefield.setid("lastname"); 

this adds needless clutter java. adds complication if id gets updated somewhere down line, <label> declaration in xml need updated (and there's no @uielement label, it's pretty invisible java side.)

is there way add id element ui:field declaration within uibinder xml itself?

uibinder uses id implement ui:field magic, no can't set xml.

the way have java constant id , use both sides:

@uifield(provided = true) final string lastnameid = document.get().createuniqueid();  @uifield inputelement lastnamefield;  …  lastnamefield.setid(last_name_id); 

and in xml:

<ui:with field="lastnameid" type="java.lang.string"/>  …  <label for="{lastnameid}">last name:</label> <input ui:field="lastnamefield" maxlength="150"/> 

note haven't tested above code type="java.lang.string", i've used class containing various identifiers instead (or rather, interface generator)

alternatives are:

  • if can, use alternate syntax <label>:

    <label>last name: <input ui:field="lastnamefield" maxlength="150"/></label> 
  • read for="" value java use in setid(), way @ least remove duplication, you'll still have issue ids possibly won't unique (as use uibinder-widget more once)

    <label ui:field="lastnamelabel" for="lastname">last name:</label> <input ui:field="lastnamefield" maxlength="150" /> 
    @uifield labelelement lastnamelabel; @uifield inputelement lastnamefield;  …  lastnamefield.setif(lastnamelabel.gethtmlfor()); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -