Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.wicketstuff.objectautocomplete.example;
 
 
 import java.util.List;

Homepage
 
 public class ListenerExamplePage extends BaseExamplePage<Car,Integer> {
 
 	private static final long serialVersionUID = 1L;
 
     public ListenerExamplePage() {
         super(new Model<Integer>());
 
     }
 
     @Override
     List<CargetAllChoices() {
         return CarRepository.allCars();
     }
 
     @Override
     String getHtmlSample() {
         return "<p>\n" +
                 "  Selected id is: <span wicket:id=\"selectedId\"></span>\n" +
                 "</p>\n\n" +
                 "<form wicket:id=\"form\">\n" +
                 "   Brand: <input type=\"text\" wicket:id=\"acField\"/>\n" +
                 "</form>";
     }
 
     @Override
     String getCodeSample() {
         return "Label label = new Label(\"selectedId\", getModel());\n" +
                 "label.setOutputMarkupId(true);\n" +
                 "Form form = new Form(\"form\");\n" +
                 "ObjectAutoCompleteField acField =\n" +
                 "        new ObjectAutoCompleteBuilder<Car,Integer>(getCarChoiceProvider())\n" +
                 "                .updateOnSelectionChange(new ObjectAutoCompleteSelectioChangeListener<Integer>() {\n" +
                 "                     public void selectionChanged(AjaxRequestTarget pTarget, IModel<Integer> pIntegerIModel) {\n" +
                 "                          label.setDefaultModel(pIntegerIModel);\n" +
                 "                          pTarget.addComponent(label);\n" +
                 "                     }\n " +
                 "                })\n" +
                 "                .build(\"acField\", new Model<Integer>());\n" +
                 "acField.registerForUpdateOnSelectionChange(label);\n" +
                 "\n" +
                 "form.add(label);\n" +
                 "form.add(acField);";
     }
 
     private void test() {
         Form form = new Form("form");
         ObjectAutoCompleteField acField =
                 new ObjectAutoCompleteBuilder<Car,Integer>(getCarChoiceProvider())
                         .build("acField"new Model<Integer>());
         Label label1 = new Label("selectedId"getModel());
         label1.setOutputMarkupId(true);
         Label label = label1;
         add(label);
         form.add(acField);
     }
 
         return new AutoCompletionChoicesProvider<Car>() {
             public Iterator<CargetChoices(String input) {
                 List<Carret = new ArrayList<Car>();
                 for (Car car : CarRepository.allCars()) {
                     if (car.getName().toLowerCase()
                             .startsWith(input.toLowerCase())) {
                         ret.add(car);
                    }
                }
                return ret.iterator();
            }
        };
    }
    @Override
    protected void initBuilder(ObjectAutoCompleteBuilder<CarIntegerpCarIntegerObjectAutoCompleteBuilder) {
        // Read-only view of the current id
        final Label label = new Label("selectedId"getModel());
        label.setOutputMarkupId(true);
        add(label);
        pCarIntegerObjectAutoCompleteBuilder.updateOnSelectionChange(new ObjectAutoCompleteSelectionChangeListener<Integer>() {
            public void selectionChanged(AjaxRequestTarget pTargetIModel<IntegerpIntegerIModel) {
                label.setDefaultModel(pIntegerIModel);
                pTarget.addComponent(label);
            }
        }).idType(Integer.class);
    }
    @Override
    protected void addIfMatch(List<CarpCarsCar pCarString pInput) {
        if (pCar.getName().toLowerCase().startsWith(pInput.toLowerCase())) {
            pCars.add(pCar);
        }
    }
New to GrepCode? Check out our FAQ X