java - How to make a pair of radio buttons in Vaadin 7 to represent True/False values but localized text? -
java - How to make a pair of radio buttons in Vaadin 7 to represent True/False values but localized text? -
i want pair of radio buttons in vaadin 7 represent boolean values each value has textual display such "active" , "inactive".
optiongroup
widget
in vaadin 7, radio buttons handled single widget, instance of optiongroup. widget contains multiple items, , if set single item selection mode, display grouping of radio buttons.
item id versus itemthe tricky part me understanding commands such "additem" bit of misnomer. not pass total item instances. rather, pass object id of item.
the additem
command takes item id, generates item instance , returns you. documented, took while me sink in. might think obligated track returned item. but, no, can utilize item id later retrieve or compare items within optiongroup.
since need not track returned items, can phone call additems
(plural) command utilize 1 line of code create multiple items multiple radio buttons.
in our case, want utilize boolean values our core data. need objects rather boolean
primitives because passing around objects. utilize boolean
class. notice boolean class couple of handy constants: boolean.true
& boolean.false
.
these boolean objects can used item ids.
example codesome illustration code using vaadin 7.3.2.
this.activecustomerradio = new optiongroup( "filter by:" ); // pass string used caption (title) of grouping of radio buttons. this.activecustomerradio.additems( boolean.true , boolean.false ); // pass item ids used in constructing item objects on our behalf. this.activecustomerradio.setitemcaption( boolean.true , "active" ); // specify textual label rather default generated value "true" & "false". this.activecustomerradio.setitemcaption( boolean.false , "inactive" ); this.activecustomerradio.setvalue( boolean.false ); // specify radio button selected default. // add together listener react user selection. this.activecustomerradio.addvaluechangelistener( new property.valuechangelistener() { @override public void valuechange ( property.valuechangeevent event ) { notification.show( "radio button" , "you chose: " + event.getproperty().getvalue().tostring() , notification.type.humanized_message ); } } );
lambda syntax by way… in java 8, can utilize new alternate lambda syntax. netbeans 8 suggest , perform conversion lambda syntax if wish.
this.activesupplierradio.addvaluechangelistener(( property.valuechangeevent event ) -> { notification.show( "radio button" , "you chose: " + event.getproperty().getvalue().tostring() , notification.type.humanized_message ); });
java radio-button vaadin vaadin7
Comments
Post a Comment