final SelectorInForm originSelector = new SelectorInForm(
"origin", "Origin", locations, this, "destination" );
originSelector.setRequired( true );
final ComponentFeedbackPanel originFeedback = new ComponentFeedbackPanel(
"originFeedback", originSelector );
add( originFeedback.setOutputMarkupId( true ) );
final SelectorInForm destinationSelector = new SelectorInForm(
"destination", "Destinatin", locations, this, "origin" );
destinationSelector.setRequired( true );
final ComponentFeedbackPanel destinationFeedback = new ComponentFeedbackPanel(
"destinationFeedback", destinationSelector );
add( destinationFeedback.setOutputMarkupId( true ) );
// Disable equal locations
originSelector.add( new AjaxFormComponentUpdatingBehavior( "onchange" )
{
@Override
protected void onUpdate( AjaxRequestTarget target )
{
// Exclude origin in destination drop down
target.add( originSelector, originFeedback, destinationSelector );
focusFirstError( target );
}
} );
destinationSelector.add( new AjaxFormComponentUpdatingBehavior( "onchange" )
{
@Override
protected void onUpdate( AjaxRequestTarget target )
{
// Exclude destination in origin drop down
target.add( destinationSelector, destinationFeedback, originSelector );
focusFirstError( target );
}
} );
// Deadline
final DateTextFieldWithPicker deadlineField = new DateTextFieldWithPicker( "deadline", "Arrival deadline", this );
deadlineField.earliestDate( new LocalDate().plusDays( 1 ) );
final ComponentFeedbackPanel deadlineFeedback = new ComponentFeedbackPanel(
"deadlineFeedback", deadlineField );
add( deadlineFeedback.setOutputMarkupId( true ) );
add( originSelector, destinationSelector, deadlineField );
add( new AjaxFallbackButton( "book", this )
{