[wicket] AJAX 程序出错,疑问
frona_lee
2013-03-03
http://www.wicket-library.com/wicket-examples-6.0.x/ajax/
调试了两天,ajax 模态窗程序 下面是一个ajax的wicket项目中,程序中只写了模态窗口部分程序,编译的时候能通过,运行的时候总是出现: Can't instantiate page using constructor 'public org.apache.wicket.examples.Index()'. Might be it doesn't exist, may be it is not visible (public). 请各位看看这个,有什么问题呢,谢谢 AjaxApplication.java public class AjaxApplication extends WicketExampleApplication { /** * Constructor. */ public AjaxApplication() { } /** * @see org.apache.wicket.examples.WicketExampleApplication#init() */ @Override protected void init() { super.init(); getApplicationSettings().setUploadProgressUpdatesEnabled(true); getResourceSettings().setThrowExceptionOnMissingResource(false); getRequestCycleSettings().addResponseFilter(new AjaxServerAndClientTimeFilter()); getDebugSettings().setAjaxDebugModeEnabled(true); mountPage("modal-window", ModalWindowPage.class); } /** * @see org.apache.wicket.Application#getHomePage() */ @Override public Class<? extends Page> getHomePage() { return Index.class; } } Index.java public class Index extends BasePage { /** * Constructor. */ public Index() { } } Index.html <?xml version="1.0" encoding="UTF-8" ?> <wicket:extend xmlns:wicket="http://wicket.apache.org"> <wicket:link> <a href="ModalWindowPage.html">Modal window</a>: javascript modal window example <br/><br/> </wicket:link> </wicket:extend> 模态窗口的程序和网站上的是一样的 ModalContent1Page.java public class ModalContent1Page extends WebPage { /** * * @param modalWindowPage * @param window */ public ModalContent1Page(final PageReference modalWindowPage, final ModalWindow window) { add(new AjaxLink<Void>("closeOK") { @Override public void onClick(AjaxRequestTarget target) { if (modalWindowPage != null) ((ModalWindowPage)modalWindowPage.getPage()).setResult("Modal window 1 - close link OK"); window.close(target); } }); add(new AjaxLink<Void>("closeCancel") { @Override public void onClick(AjaxRequestTarget target) { if (modalWindowPage != null) ((ModalWindowPage)modalWindowPage.getPage()).setResult("Modal window 1 - close link Cancel"); window.close(target); } }); add(new DateTimeField("dateTimeField")); final ModalWindow modal; add(modal = new ModalWindow("modal")); modal.setCookieName("modal window 2"); modal.setResizable(false); modal.setInitialWidth(30); modal.setInitialHeight(15); modal.setWidthUnit("em"); modal.setHeightUnit("em"); modal.setCssClassName(ModalWindow.CSS_CLASS_GRAY); modal.setPageCreator(new ModalWindow.PageCreator() { @Override public Page createPage() { return new ModalContent2Page(modal); } }); modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { @Override public boolean onCloseButtonClicked(AjaxRequestTarget target) { target.appendJavaScript("alert('You can\\'t close this modal window using close button." + " Use the link inside the window instead.');"); return false; } }); add(new AjaxLink<Void>("open") { @Override public void onClick(AjaxRequestTarget target) { modal.show(target); } }); } } ModalContent2Page.java public class ModalContent2Page extends WebPage { /** * @param window */ public ModalContent2Page(final ModalWindow window) { add(new AjaxLink<Void>("close") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { window.close(target); } }); } } ModalPanel1.java public class ModalPanel1 extends Panel { /** * @param id */ public ModalPanel1(String id) { super(id); add(new DateTimeField("dateTimeField") { /** * @see org.apache.wicket.extensions.yui.calendar.DateTimeField#configure(java.util.Map) */ @Override protected void configure(Map<String, Object> widgetProperties) { super.configure(widgetProperties); // IE 6 breaks layout with iframe - is that a YUI bug? widgetProperties.put("iframe", false); } }); } } ModalContent1Page.html <?xml version="1.0" encoding="UTF-8" ?> <html xmlns:wicket="http://wicket.apache.org"> <head> <title>This is modal window</title> <style type="text/css"> body { font-family: verdana, sans-serif; font-size: 82%; background-color: white; } </style> </head> <body> Modal WINDOW content. <p> <a wicket:id="closeOK">Close this window with result "OK"</a><br/> <a wicket:id="closeCancel">Close this window with result "Cancel"</a><br/> </p> <p> <div wicket:id="modal"></div> <a wicket:id="open">Open another modal dialog</a> </p> <p> <div>An example of a component that uses header contributions</div> <div wicket:id="dateTimeField" /> </p> </body> </html> ModalContent2Page.html <?xml version="1.0" encoding="UTF-8" ?> <html xmlns:wicket="http://wicket.apache.org"> <head> <title>Modal dialog</title> <style type="text/css"> body { font-family: verdana, sans-serif; font-size: 82%; background-color: #FFFEC4; } </style> </head> <body> This is modal window opened from another modal window. This one is not resizable. The window dimensions are specified in relative units (em). <p> <a wicket:id="close">Close this window</a><br/> </p> </body> </html> Modal1Panel1.html <?xml version="1.0" encoding="UTF-8" ?> <wicket:panel xmlns:wicket="http://wicket.apache.org"> <div style="margin: 1em"> This is panel content! <p> Date text field to demonstrate AJAX header contribution <span wicket:id="dateTimeField"></span> </p> </div> </wicket:panel> ModalWindowPage.java public class ModalWindowPage extends BasePage { private String result; /** */ public ModalWindowPage() { final Label result; add(result = new Label("result", new PropertyModel<String>(this, "result"))); result.setOutputMarkupId(true); /* * First modal window */ final ModalWindow modal1; add(modal1 = new ModalWindow("modal1")); modal1.setCookieName("modal-1"); modal1.setPageCreator(new ModalWindow.PageCreator() { @Override public Page createPage() { return new ModalContent1Page(ModalWindowPage.this.getPageReference(), modal1); } }); modal1.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { target.add(result); } }); modal1.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { @Override public boolean onCloseButtonClicked(AjaxRequestTarget target) { setResult("Modal window 1 - close button"); return true; } }); add(new AjaxLink<Void>("showModal1") { @Override public void onClick(AjaxRequestTarget target) { modal1.show(target); } }); /* * Second modal window */ final ModalWindow modal2; add(modal2 = new ModalWindow("modal2")); modal2.setContent(new ModalPanel1(modal2.getContentId())); modal2.setTitle("This is modal window with panel content."); modal2.setCookieName("modal-2"); modal2.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() { @Override public boolean onCloseButtonClicked(AjaxRequestTarget target) { setResult("Modal window 2 - close button"); return true; } }); modal2.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() { @Override public void onClose(AjaxRequestTarget target) { target.add(result); } }); add(new AjaxLink<Void>("showModal2") { @Override public void onClick(AjaxRequestTarget target) { modal2.show(target); } }); } /** * @return the result */ public String getResult() { return result; } /** * @param result * the result to set */ public void setResult(String result) { this.result = result; } } ModalWindowPage.html <?xml version="1.0" encoding="UTF-8" ?> <wicket:extend xmlns:wicket="http://wicket.apache.org"> Last modal window result: <span wicket:id="result"></span> <div wicket:id="modal1"></div> <a wicket:id="showModal1">Show modal dialog with a page</a> <br/> <div wicket:id="modal2"></div><br/> <a wicket:id="showModal2">Show modal dialog with panel</a> </wicket:extend> BasePage.java public class BasePage extends WicketExamplePage { /** * Constructor */ public BasePage() { add(new BookmarkablePageLink<Void>("back", Index.class).setAutoEnable(true)); } } BasePage.html <?xml version="1.0" encoding="UTF-8" ?> <html xmlns:wicket="http://wicket.apache.org"> <head> <title>Wicket Examples - Ajax</title> <link rel="stylesheet" type="text/css" href="style.css"/> </head> <body> <span wicket:id="mainNavigation"/> <a href="Index.html" wicket:id="back">[go back]</a><p/> <wicket:child/> </body> </html> WicketExamplePage.java public class WicketExamplePage extends WebPage { /** * */ private static final long serialVersionUID = 1L; /** * Constructor */ public WicketExamplePage() { this(new PageParameters()); } /** * Constructor * * @param pageParameters */ public WicketExamplePage(final PageParameters pageParameters) { super(pageParameters); final String packageName = getClass().getPackage().getName(); add(new WicketExampleHeader("mainNavigation", Strings.afterLast(packageName, '.'), this)); explain(); } /** * Construct. * * @param model */ public WicketExamplePage(IModel<?> model) { super(model); } /** * Override base method to provide an explanation */ protected void explain() { } } WicketExampleApplication.java public abstract class WicketExampleApplication extends WebApplication { /** * prevent wicket from launching a java application window on the desktop <br/> * once someone uses awt-specific classes java will automatically do so and allocate a window * unless you tell java to run in 'headless-mode' */ static { System.setProperty("java.awt.headless", "true"); } /** * Constructor. */ public WicketExampleApplication() { } /** * @see org.apache.wicket.protocol.http.WebApplication#init() */ @Override protected void init() { // WARNING: DO NOT do this on a real world application unless // you really want your app's passwords all passed around and // stored in unencrypted browser cookies (BAD IDEA!)!!! // The NoCrypt class is being used here because not everyone // has the java security classes required by Crypt installed // and we want them to be able to run the examples out of the // box. getSecuritySettings().setCryptFactory( new ClassCryptFactory(NoCrypt.class, ISecuritySettings.DEFAULT_ENCRYPTION_KEY)); getDebugSettings().setDevelopmentUtilitiesEnabled(true); } } 错误: ERROR - DefaultExceptionMapper - Unexpected error occurred org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public org.apache.wicket.examples.Index()'. Might be it doesn't exist, may be it is not visible (public). at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:193) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:66) at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:133) at org.apache.wicket.core.request.handler.PageProvider.resolvePageInstance(PageProvider.java:278) at org.apache.wicket.core.request.handler.PageProvider.getPageInstance(PageProvider.java:166) at org.apache.wicket.request.handler.render.PageRenderer.getPage(PageRenderer.java:78) at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:94) at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:244) at org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165) at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:840) at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:254) at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:211) at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:282) at org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:244) at org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:188) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:267) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Thread.java:722) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:174) ... 28 more Caused by: java.lang.NoClassDefFoundError: org/apache/wicket/devutils/debugbar/DebugBar at org.apache.wicket.examples.WicketExampleHeader.<init>(WicketExampleHeader.java:48) at org.apache.wicket.examples.WicketExamplePage.<init>(WicketExamplePage.java:54) at org.apache.wicket.examples.WicketExamplePage.<init>(WicketExamplePage.java:41) at org.apache.wicket.examples.BasePage.<init>(BasePage.java:28) at org.apache.wicket.examples.Index.<init>(Index.java:16) ... 33 more Caused by: java.lang.ClassNotFoundException: org.apache.wicket.devutils.debugbar.DebugBar at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526) ... 38 more INFO - PropertiesFactory - Loading properties files from jar:file:/E:/Tomcat%206.0/wtpwebapps/ajax/WEB-INF/lib/wicket-core-6.5.0.jar!/org/apache/wicket/Application_zh_CN.properties with loader org.apache.wicket.resource.IsoPropertiesFilePropertiesLoader@1e32705 INFO - PropertiesFactory - Loading properties files from jar:file:/E:/Tomcat%206.0/wtpwebapps/ajax/WEB-INF/lib/wicket-core-6.5.0.jar!/org/apache/wicket/Application.properties with loader org.apache.wicket.resource.IsoPropertiesFilePropertiesLoader@1e32705 INFO - xServerAndClientTimeFilter - 638ms server time taken for request response size: 11190 |
|
frona_lee
2013-03-03
帮忙看看~谢谢
|
|
freezingsky
2013-03-03
框架太多,特别像这种类型的框架,估计用的人太少。。。建设你去官方论坛,或者到国外的网站看看。
另外,我觉得你还不如用JSF呢。 |
|
avyi
2013-03-04
wicket的ajax需要几个js脚本的支持,参考wicket-examples源代码中的js、css等,copy过来就行了,特别是modalwindow的例子
|
|
lvwenwen
2013-03-04
modalwindow的例子
|
|
solo.Homme
2013-05-25
WicketExampleApplication.java init() 方法
getDebugSettings().setDevelopmentUtilitiesEnabled(true); 这句去掉 或者设成false吧 报错很明显写着Caused by: java.lang.ClassNotFoundException: org.apache.wicket.devutils.debugbar.DebugBar 应该是你下的源码包不完全把 建议把wicket example 整个下下来 然后用 mvn install jetty:run 跑起来 页面与http://www.wicket-library.com/wicket-examples-6.0.x 一样 |
|
黑白配
2013-06-24
我同意 为什么要用wicket 好麻烦
|