private void addDateRangeExample ( ) { add ( new WHeading ( HeadingLevel . H2 , "Example of a date range component" ) ) ; WFieldSet dateRange = new WFieldSet ( "Enter the expected arrival and departure dates." ) ; add ( dateRange ) ; WPanel dateRangePanel = new WPanel ( ) ; dateRangePanel . setLayout ( new FlowLayout ( FlowLayout . LEFT , Size . MEDIUM ) ) ; dateRange . add ( dateRangePanel ) ; final WDateField arrivalDate = new WDateField ( ) ; final WDateField departureDate = new WDateField ( ) ; //One could add some validation rules around this so that "arrival" was always earlier than or equal to "departure" WLabel arrivalLabel = new WLabel ( "Arrival" , arrivalDate ) ; arrivalLabel . setHint ( "dd MMM yyyy" ) ; WLabel departureLabel = new WLabel ( "Departure" , departureDate ) ; departureLabel . setHint ( "dd MMM yyyy" ) ; dateRangePanel . add ( arrivalLabel ) ; dateRangePanel . add ( arrivalDate ) ; dateRangePanel . add ( departureLabel ) ; dateRangePanel . add ( departureDate ) ; //subordinate control to ensure that the departure date is only enabled if the arrival date is populated WSubordinateControl control = new WSubordinateControl ( ) ; add ( control ) ; Rule rule = new Rule ( new Equal ( arrivalDate , null ) ) ; control . addRule ( rule ) ; rule . addActionOnTrue ( new Disable ( departureDate ) ) ; rule . addActionOnFalse ( new Enable ( departureDate ) ) ; control . addRule ( rule ) ; }
Add date range example .