I have a panel which is backed by an over all CompoundPropertyModel. It has
an inner panel which is my search panel and Labels. Here is the search
panel code.
public class SearchPatientPanel extends Panel
{
private static final long serialVersionUID = 8413569236371190758L;
private PatientAutoCompleteTextField patientAutoCompleteTextField;
private Label searchLabel;
public SearchPatientPanel( String id )
{
super( id );
setOutputMarkupId( true );
final ModalWindow addPatientWindow;
add( addPatientWindow = new ModalWindow( "addPatientWindow" ) );
searchLabel = new Label( "searchLabel", "Enter any part of the
patient's
name." );
searchLabel.setOutputMarkupId( true );
searchLabel.setVisible( false );
add( searchLabel );
patientAutoCompleteTextField = new PatientAutoCompleteTextField(
"lastName", new PatientAutoCompleteTextRenderer(), addPatientWindow );
patientAutoCompleteTextField.setOutputMarkupId( true );
patientAutoCompleteTextField.setVisible( false );
add( patientAutoCompleteTextField );
add( new AjaxLink( "search" )
{
private static final long serialVersionUID =
-6622359946182548552L;
@Override
public void onClick( AjaxRequestTarget target )
{
SearchPatientPanel.this.patientAutoCompleteTextField.setVisible( true
);
SearchPatientPanel.this.searchLabel.setVisible( true );
target.addComponent(
SearchPatientPanel.this );
}
});
}
public void hideSearch()
{
patientAutoCompleteTextField.setVisible( false );
patientAutoCompleteTextField.setModel( new Model() );
searchLabel.setVisible( false );
}
}
The AutoCompleteTextField has an AjaxUpdatingBehavior.
this.add( new AjaxFormComponentUpdatingBehavior( "onchange" )
{
private static final long serialVersionUID = 1L;
public void onUpdate( AjaxRequestTarget target )
{
String selectedPatient = getModelValue();
if( StringUtils.isNotEmpty( selectedPatient ) )
{
if( StringUtils.contains( selectedPatient, "New
Patient" ) )
{
System.out.println( "user wants to
create a new patient" );
addPatientWindow.show( target );
}
else
{
Patient patient = getPatient(
selectedPatient ) );
target.addComponent( patientDataPanel );
hideSearch( target );
}
}
}
});
I type a couple characters into the autocomplete and then select from the
list. The first time the onChange event is fired, I get the input. The
second time the event is fired I get the selected text.
Thanks
Mike
Martin Funk-3 wrote:
>
> Hi Michal,
>
> could you come up with some code?
>
> mf
>
> 2008/2/22, Bushby <[EMAIL PROTECTED]>:
>>
>>
>> I have an AutoCompleteTextField which searches for a person object. When
>> a
>> person is selected from the auto complete, I want to update the panel and
>> the model with the person's information. I have tried adding an
>> AjaxFormComponentUpdatingBehavior, but it gets called twice. Once with
>> the
>> text entered by the user, and the second with the text from the auto
>> complete. How do I capture just the selection event?
>>
>> Thanks
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/AutoCompleteTextField-user-selection-tp15634452p15634452.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/AutoCompleteTextField-user-selection-tp15634452p15676689.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]