have you looked at the wicketstuff-scriptaculous project?  there's an
autocomplete text field that should be what you need.

On Tue, Apr 15, 2008 at 1:53 PM, Ryan Gravener <[EMAIL PROTECTED]>
wrote:

> Set the model object in getTextValue(java.lang.Object object)
>
> but in your renderChoice(*) do not call getTextValue!!!  make another
> method called getStringValue() and return the actor name, then in
> getTextValue set the modelobject and return getStringValue().
>
> I am not positive this will work.
>
> On Tue, Apr 15, 2008 at 2:23 PM, Patel, Sanjay <[EMAIL PROTECTED]>
> wrote:
> > Hi,
> >
> >
> >
> >  I am trying to implement a simple auto complete AJAX text box which
> gives me the names of actors as I type in (by searching and getting the list
> of actors from database),  and set the Model Object (which is Actor selected
> from the auto complete drop down) for the Panel (in which this Auto complete
> Text Field lies); In adding a Behavior to the field, I am trying to do a
> setModel( ) for the panel (which contains the AutoCompleteTextField), but
> when I get the object (autoCompleteTextField.getModelObject( )) inside the
> behavior anonymous class, It returns a string, even though outside I seem to
> be getting model Object fine (outside as in outside the anonymous class
> declaration). Here's the full code as I know it.
> >
> >
> >
> >  final AutoCompleteTextField actorInformationAutoCompleteTextField = new
> AutoCompleteTextField("input-auto-complete-actorForPanel-search", new
> Model((Actor) getModel().getObject()),
> >
> >                         new AbstractAutoCompleteRenderer() {
> >
> >                               private static final long serialVersionUID
> = 1L;
> >
> >
> >
> >                               /**
> >
> >                                * [EMAIL PROTECTED]
> >
> >                                */
> >
> >                               @Override
> >
> >                               protected String getTextValue(Object
> object) {
> >
> >  return ((Actor) object).getLastName() + COMMA_SEPARATOR + (((Actor)
> object).getFirstName());
> >
> >                               }
> >
> >
> >
> >                               /**
> >
> >                                * [EMAIL PROTECTED]
> >
> >                                */
> >
> >                               @Override
> >
> >                               protected void renderChoice(Object object,
> Response response, String criteria) {
> >
> >
> response.write(getTextValue(object));
> >
> >
> >
> >                               }
> >
> >                         }) {
> >
> >
> >
> >                   private static final long serialVersionUID = 1L;
> >
> >
> >
> >                   /**
> >
> >                    * [EMAIL PROTECTED]
> >
> >                    */
> >
> >                   @Override
> >
> >                   @SuppressWarnings("unchecked")
> >
> >                   protected final Iterator<Actor> getChoices(final
> String input) {
> >
> >                         System.out.println(" getChoices called
> -------------------> ");
> >
> >                         if (Strings.isEmpty(input)) {
> >
> >                               return Collections.EMPTY_LIST.iterator();
> >
> >                         }
> >
> >
> >
> >                         // our list of choices (this is displayed with
> when user starts typing something)
> >
> >                         final List<Actor> choices = new
> ArrayList<Actor>(10);
> >
> >
> >
> >                         // set the search key for data provider ...
> >
> >                         List<Actor> actors = new
> ActorDataProvider(input, 10).search(0, 10).getCollection();
> >
> >
> >
> >                         for (int i = 0; i < actors.size(); i++) {
> >
> >                               System.out.println(" Inside actors loop
> >>>>>>>>>>>>");
> >
> >                               System.out.println(" Actor[i]
> ------------> " + actors.get(i).getFirstName());
> >
> >                               final Actor actorTemp = actors.get(i);
> >
> >
> >
> >  if (actorTemp.getFirstName().trim().contains(input) ||
> actorTemp.getLastName().contains(input)) {
> >
> >                                     choices.add(actorTemp);
> >
> >
> >
> >                               }
> >
> >
> >
> >                               if (choices.size() == 10) {
> >
> >                                     break;
> >
> >                               }
> >
> >                         }
> >
> >
> >
> >                         return choices.iterator();
> >
> >                   }
> >
> >
> >
> >             };
> >
> >
> >
> >
> >
> >  Here is where I add Behavior:
> >
> >             actorInformationAutoCompleteTextField.add(new
> AjaxFormSubmitBehavior("onchange") {
> >
> >                   private static final long serialVersionUID = 1L;
> >
> >
> >
> >                   /**
> >
> >                    * [EMAIL PROTECTED]
> >
> >                    */
> >
> >                   @Override
> >
> >                   protected final void onSubmit(final AjaxRequestTarget
> target) {
> >
> >                         System.out.println(" onSubmit( ) for
> AjaxFormSubmitBehavior called ....");
> >
> >                         // set the Model for the panel (with model
> object actor)
> >
> >  AbstractActorInformationPanel.this.setModelObject((Actor)
> >
> >
>  
> AbstractActorInformationPanel.this.setReviewPlan(getReviewPlanForActor((Actor)
> actorInformationAutoCompleteTextField .getModelObject()));
> <------------------------ When I try to do getModelObject( ) here it gives
> me Class Cast Exception! (Cannot convert from String to Actor)
> >
> >                   }
> >
> >
> >
> >                   /**
> >
> >                    * [EMAIL PROTECTED]
> >
> >                    */
> >
> >                   @Override
> >
> >                   protected final void onError(final AjaxRequestTarget
> target) {
> >
> >                         System.out.println(" onError( ) for
> AjaxFormSubmitBehavior called ....");
> >
> >                   }
> >
> >             });
> >
> >
> >
> >
> >
> >  Can someone tell me what's wrong?
> >
> >
> >  ---------------------------------------------------------------------
> >  To unsubscribe, e-mail: [EMAIL PROTECTED]
> >  For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
>
> --
> Ryan Gravener
> http://ryangravener.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to