private void addExampleUsingStringArray ( ) { add ( new WHeading ( HeadingLevel . H3 , "WCheckBoxSelect created using a String array" ) ) ; String [ ] options = new String [ ] { "Dog" , "Cat" , "Bird" , "Turtle" } ; final WCheckBoxSelect select = new WCheckBoxSelect ( options ) ; select . setToolTip ( "Animals" ) ; select . setMandatory ( true ) ; final WTextField text = new WTextField ( ) ; text . setReadOnly ( true ) ; text . setText ( NO_SELECTION ) ; WButton update = new WButton ( "Select Animals" ) ; update . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { String output = select . getSelected ( ) . isEmpty ( ) ? NO_SELECTION : "The selected animals are: " + select . getSelected ( ) ; text . setText ( output ) ; } } ) ; select . setDefaultSubmitButton ( update ) ; WLabel animalLabel = new WLabel ( "A selection is required" , select ) ; animalLabel . setHint ( "mandatory" ) ; add ( animalLabel ) ; add ( select ) ; add ( update ) ; add ( text ) ; add ( new WAjaxControl ( update , text ) ) ; }
This example creates the WCheckBoxSelect from an array of Strings .