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
 
 
 	private static final long serialVersionUID = 1L;
 
     public ComplexChoicesExamplePage() {
         super(new Model<Integer>());
     }
 
     @Override
     List<CargetAllChoices() {
         return CarRepository.allCars();
     }
 
     @Override
     protected void initBuilder(ObjectAutoCompleteBuilder<CarIntegerpBuilder) {
         super.initBuilder(pBuilder);
     }
 
     @Override
     String getCodeSample() {
         return "ObjectAutoCompleteBuilder<Car,Integer> builder =\n" +
                 "       new ObjectAutoCompleteBuilder<Car,Integer>( ... ).\n\n" +
                 "       autoCompleteResponseRenderer(new ObjectAutoCompleteResponseRenderer<Car>() {\n" +
                 "\n" +
                 "            public void onRequest(Iterator<Car> pComps, WebResponse pResponse,String pInput) {\n" +
                 "                List<Car> without = new ArrayList<Car>();\n" +
                 "                pResponse.write(\"<div>\");\n" +
                 "                pResponse.write(\"<div>With 'a':</div><ul>\");\n" +
                 "                while (pComps.hasNext()) {\n" +
                 "                    Car car = pComps.next();\n" +
                 "                    if (car.getName().contains(\"a\")) {\n" +
                 "                        renderObject(car,pResponse,pInput);\n" +
                 "                    } else {\n" +
                 "                        without.add(car);\n" +
                 "                    }\n" +
                 "                }\n" +
                 "                pResponse.write(\"</ul>\");\n" +
                 "                if (without.size() > 0) {\n" +
                 "                    pResponse.write(\"<div>Without 'a':</div><ul>\");\n" +
                 "                    for (Car car : without) {\n" +
                 "                        renderObject(car,pResponse,pInput);\n" +
                 "                    }\n" +
                 "                    pResponse.write(\"</ul>\");\n" +
                 "                }\n" +
                 "                pResponse.write(\"</div>\");\n" +
                 "            }\n" +
                 "        }\n" +
                 "\n" +
                 "ObjectAutoCompleteField acField = \n" +
                 "       builder.build(\"acField\", new Model<Integer>());\n" +
                 "form.add(acField);";
     }
 
     // Used for C&P in the string above
     private void test() {
         Form form = new Form("form");
         ObjectAutoCompleteBuilder<Car,Integerbuilder =
                 new ObjectAutoCompleteBuilder<Car,Integer>(
                         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();
                            }
                        }
        ObjectAutoCompleteField acField =
                builder.build("acField"new Model<Integer>());
        form.add(acField);
    }
        return new ObjectAutoCompleteResponseRenderer<Car>() {
            @Override
            public void onRequest(Iterator<CarpCompsWebResponse pResponse,String pInput) {
                List<Carwithout = new ArrayList<Car>();
                pResponse.write("<div>");
                pResponse.write("<div class=\"choiceHeader\">With 'a':</div><ul>");
                while (pComps.hasNext()) {
                    Car car = pComps.next();
                    if (car.getName().contains("a")) {
                        renderObject(car,pResponse,pInput);
                    } else {
                        without.add(car);
                    }
                }
                pResponse.write("</ul>");
                if (without.size() > 0) {
                    pResponse.write("<div class=\"choiceHeader\">Without 'a':</div><ul>");
                    for (Car car : without) {
                        renderObject(car,pResponse,pInput);
                    }
                    pResponse.write("</ul>");
                }
                pResponse.write("</div>");
            }
        };
    }
    @Override
    String getHtmlSample() {
        return "<form wicket:id=\"form\">\n" +
                " Brand: <input type=\"text\" wicket:id=\"acField\"/>\n" +
                "</form>";
    }
    @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