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;
 
         super(new Model<Integer>());
     }
 
     @Override
     List<CargetAllChoices() {
         return CarRepository.allCars();
     }
 
     @Override
     protected void initBuilder(ObjectAutoCompleteBuilder<Car,IntegerpBuilder) {
         super.initBuilder(pBuilder);
         pBuilder.readOnlyRenderer(new ObjectReadOnlyRenderer<Integer>() {
             public Component getObjectRenderer(String idfinal IModel<IntegerpIModelIModel<StringpSearchTextModel) {
                 Fragment frag =  new Fragment(id,"readOnlyView"ReadOnlyObjectRendererExamplePage.this);
                 frag.add(new Label("search",pSearchTextModel));
                 frag.add(new Label("id",pIModel));
                 frag.add(new Label("object",new AbstractReadOnlyModel() {
                     public Object getObject() {
                         if (pIModel != null && pIModel.getObject() != null) {
                             for (Car car : CarRepository.allCars()) {
                                 if (car.getId() == pIModel.getObject()) {
                                     return "[id = " + car.getId()
                                             + ",name = " + car.getName() + "]";
                                 }
                             }
                         }
                         return null;
                     }
                 }));
                 return frag;
             }
         })
                 .searchOnClick()
                 .idType(Integer.class);
     }
 
     @Override
     String getCodeSample() {
         return "ObjectAutoCompleteField<Car,Integer> acField =\n" +
                 "        new ObjectAutoCompleteBuilder<Car,Integer>(getAcChoicesProvider()) \n" +
                 "                .readOnlyRenderer(new ReadOnlyObjectRenderer<Integer>() {\n" +
                 "                    public Component getObjectRenderer(String id, IModel<Integer> pIModel,\n" +
                 "                                                       Model<String> pSearchTextModel) {\n" +
                 "                        Fragment frag =  new Fragment(id,\"readOnlyView\");\n" +
                 "                        frag.add(new Label(\"search\",pSearchTextModel));\n" +
                 "                        frag.add(new Label(\"id\",pIModel));\n" +
                 "                        frag.add(new Label(\"object\",new AbstractReadOnlyModel() {\n" +
                 "                              public Object getObject() {\n" +
                 "                                  if (pIModel != null && pIModel.getObject() != null) {\n" +
                 "                                       for (Car car : CarRepository.allCars()) {\n" +
                 "                                           if (car.getId() == pIModel.getObject()) {\n" +
                 "                                              return \"[id = \" + car.getId()\n" +
                 "                                                   + \",name = \" + car.getName() + \"]\";\n" +
                 "                                           }\n" +
                 "                                       }\n" +
                 "                                  }\n" +
                 "                                  return null;\n" +
                 "                              }\n" +
                 "                        }));" +
                 "                        return frag;\n" +
                 "                    }\n" +
                 "               })\n" +
                "                .searchOnClick()\n" +
                "                .build();\n" +
                "form.add(acField);";
    }
    @Override
    String getHtmlSample() {
        return "<form wicket:id=\"form\">\n" +
                "  Brand: <input type=\"text\" wicket:id=\"acField\" />\n" +
                "</form>\n" +
                "\n" +
                "<wicket:fragment wicket:id=\"readOnlyView\">\n" +
                "  Name: <span wicket:id=\"search\">[search]</span>\n" +
                "  Id:   <span wicket:id=\"id\">[id]</span>\n" +
                "</wicket:fragment>";
    }
    @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