开发者

java wicket error!

开发者 https://www.devze.com 2023-03-12 13:56 出处:网络
This is my code, package com.mywicketapp; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator;

This is my code,

package com.mywicketapp;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormSubmitBehavior;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.Model;
import org.apache.wicket.util.string.Strings;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.extensions.ajax.markup
   .html.autocomplete.AutoCompleteTextField;

public class  HomePage extends WebPage
{
  public HomePage()
  {
  Form form = new Form("form");
  add(form);

  final AutoCompleteTextField field = 
  new AutoCompleteTextField("auto", new Model(""))
  {
  protected Iterator getChoices(String input)
  {
  if (Strings.isEmpty(input))
 {
 return Collections.EMPTY_LIST.iterator();
  }

  List choices = new ArrayList(10);

 Locale[] locales = Locale.getAvailableLocales();

 for (int i = 0; i < locales.length; i++)
 {
  final Locale locale = locales[i];
  final String country = locale.getDisplayCountry();

if (country.toUpperCase().startsWith(input.toUpperCase()))
 {
  choices.add(country);
  if (choices.size() == 10)
 {
  break;
  }
 }
 }
 return choices.iterator();
 }
  };
  form.add(field);

final Label label = new 
 Label("selectedValue", field.getModel());
  label.setOutputMarkupId(true);
 form.add(label);
 field.add(new AjaxFormSubmitBehavior(form, "onchange")
 {
  protected void onSubmit(AjaxRequestTarget target)
  {
 target.addComponent(label);
 }

  @Override
 protected void onError(AjaxRequestTarget target)
 {
  }
  });
  }
}

This is my application code:

package com.mywicketapp;

import org.apache.wicket.protocol.http.WebApplication;

/**
 * Application object for your web application. If you want to run this application without deploying, run the Start class.
 * 
 * @see com.mywicketapp.Start#main(String[])
 */
public class WicketApplication extends WebApplication
{    
    /**
     * Constructor
     */
    public WicketApplication()
    {
    }

    /**
     * @see org.apache.wicket.Application#getHomePage()
     */
    public Class<HomePage> getHomePage(){
          return HomePage.class;  
          }

}

Some html:

<html>
  <head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
  The textfield below will autocomplete country names
  <br><hr>
  <form wicket:id="form">
 Selected value is: <span wicket:id="selectedValue"></span>
 <br/>
  Country: <开发者_如何学运维;input type="text" wicket:id="auto" size="20"/>
 </form>
  </body>
</html>

And the error:

- log                        - Logging to org.slf4j.impl.Log4jLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
>>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP
INFO  - log                        - jetty-6.1.25
INFO  - log                        - NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
WARN  - log                        - failed wicket.mywicketapp: java.lang.ClassCastException: wicket.extensions.Initializer cannot be cast to org.apache.wicket.IInitializer
ERROR - log                        - Failed startup of context org.mortbay.jetty.webapp.WebAppContext@66e7b3f2{/,src/main/webapp}
java.lang.ClassCastException: wicket.extensions.Initializer cannot be cast to org.apache.wicket.IInitializer
    at org.apache.wicket.Application.addInitializer(Application.java:864)
    at org.apache.wicket.Application.load(Application.java:938)
    at org.apache.wicket.Application.initializeComponents(Application.java:715)
    at org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:732)
    at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:662)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1272)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:489)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.mywicketapp.Start.main(Start.java:43)
INFO  - log                        - Started SelectChannelConnector@0.0.0.0:8080


Looks to me like you have a version incompatibility problem... Check to make sure that the version of wicket-extensions that you're using is compatible with your wicket version. The wicket.extensions.Initializer that's getting loaded and causing the exception is surely getting loaded up by your AutoCompleteTextField.

0

精彩评论

暂无评论...
验证码 换一张
取 消