-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hey still working through this to-do tutorial. I've finally got derby working with this app, but when i recompile Im getting a java.lang.ClassNotFoundException: org.zktest.doa.EventController. That is my controller, and I know it is there and that is the fully qualified name for it. Even though "doa" was a type-o, it is consistent through out my code. Is there a host mode like in GWT where I can set breaks to help figure this out? Or any ideas of what it might be. The full read out the log is below. I can attach the the zul and EventController.java if it would be helpful.
Michael
SEVERE: Servlet.service() for servlet zkLoader threw exception org.zkoss.zk.ui.UiException: java.lang.ClassNotFoundException: org.zktest.doa.EventController at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.zkoss.lang.Classes.newInstance(Classes.java:78) at org.zkoss.lang.Exceptions.wrap(Exceptions.java:164) at org.zkoss.zk.ui.UiException$Aide.wrap(UiException.java:46) at org.zkoss.zk.ui.metainfo.ComponentInfo.resolveComposer(ComponentInfo.java:345) at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:593) at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:587) at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:531) at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:498) at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:378) at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:299) at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:230) at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:166) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 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:128) 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:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.ClassNotFoundException: org.zktest.doa.EventController at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at org.zkoss.lang.Classes.forNameByThread(Classes.java:199) at org.zkoss.zk.ui.impl.PageImpl.resolveClass(PageImpl.java:360) at org.zkoss.zk.ui.metainfo.ComponentInfo.toComposer(ComponentInfo.java:403) at org.zkoss.zk.ui.metainfo.ComponentInfo.toComposer(ComponentInfo.java:395) at org.zkoss.zk.ui.metainfo.ComponentInfo.toComposers(ComponentInfo.java:363) at org.zkoss.zk.ui.metainfo.ComponentInfo.resolveComposer(ComponentInfo.java:340)
I'd suggest you give information about your development environment and attach the source code.
Using eclipse 3.5. I declare the controller in the index.zul window component. EventController is in package org.zktest.doa with ToDoEvent and EventDAO. Index.zul and EventController code below.
Index.zul
<?page title="To Do List!!"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?> <window id="win" title="To Do tutorial" border="normal" width="500px" height="500px" apply="org.zktest.doa.EventController"> <listbox id="box" multiple="true" rows="5" width="100%" model="@{win$composer.allEvents, load-after='add.onClick, delete.onClick, update.onClick'}" selectedItem="@{win$composer.current}" > <listhead> <listheader label="Item" width="50%" ></listheader> <listheader label="Priority" width="25%"></listheader> <listheader label="Date" width="25%"></listheader> </listhead> <listitem self="@{each='event'}" value="@{event}" > <listcell label="@{event.name}" ></listcell> <listcell label="@{event.priority}"></listcell> <listcell lable="@{event.date}"></listcell> </listitem> </listbox> <groupbox> <caption label="Event"/> Item:<textbox id="name" cols="50" value="@{win$composer.current.name}"></textbox> Priority:<intbox id="priority" cols="1" value="@{win$composer.current.priority}"></intbox> Date:<datebox id="date" cols="8" value="@{win$composer.current.date}"></datebox> <button id="add" label="Add" height="36px" width="24px" /> <button id="update" label="Update" height="48px" width="24px" /> <button id="delete" label="Delete" height="48px" width="24px" /> </groupbox> </window>
EventController
package org.zktest.doa; import java.util.List; import java.util.UUID; import org.zkoss.zk.ui.util.GenericAutowireComposer; import org.zkoss.zul.Listbox; public class EventController extends GenericAutowireComposer { EventDAO eventDAO = new EventDAO(); ToDoEvent current = new ToDoEvent(); private Listbox box; public List<ToDoEvent> getAllEvents() { return eventDAO.findAll(); } public ToDoEvent getCurrent() { return current; } public void setCurrent(ToDoEvent current) { this.current = current; } public void onClick$add() { // insert into database System.out.println("Trying to add a new line"); ToDoEvent newEvt = new ToDoEvent(UUID.randomUUID().toString(), current.getName(), current.getPriority(), current.getDate()); eventDAO.insert(newEvt); } public void onClick$update() { if (box.getSelectedItem() != null) { // update database eventDAO.update((ToDoEvent) box.getSelectedItem().getValue()); } } public void onClick$delete() { if (box.getSelectedItem() != null) { eventDAO.delete((ToDoEvent) box.getSelectedItem().getValue()); } } }
Well, I know this may sound trivial, but nothing is *apparently* wrong, so:
1) with EventController open in an editor, go to the Outline view. Right click the EventController class declaration, and select Copy Qualified Name. Paste that into the value of your apply attribute.
2) Look in the project properties and get the location of the Default output folder from the Java Build Path->Source tab. Then, make sure the .class file is in that location.
Nothing seems out of order from your source samples so I don't know what else to suggest.
Cary
1) Do you have Build Automatically turned on? I never do because it's a PITA.
2) Click on the project and look in your Problems view to see if there are issues listed there to resolve.
3) If 2) doesn't show any problems, do a Project->Build Project
ha.... when i "copied" the derby.jar into the web-inf library i must had mv instead.... doh! Which caused the above error.
But now my controller isn't working properly. It will not insert to the database from the onClick$add() method. when I hit the add button, it will refresh the listbox, but it doesnt seem to be calling the onClick$add method. I threw in a system.out.println in there just to see if it was being used, it isn't. Fix one problem to find another.
package org.zktest.doa; import java.util.List; import java.util.UUID; import org.zkoss.zk.ui.util.GenericAutowireComposer; import org.zkoss.zul.Listbox; public class EventController extends GenericAutowireComposer { EventDAO eventDAO = new EventDAO(); ToDoEvent current = new ToDoEvent(); private Listbox box; public List<ToDoEvent> getAllEvents() { return eventDAO.findAll(); } public ToDoEvent getCurrent() { return current; } public void setCurrent(ToDoEvent current) { this.current = current; } public void onClick$add() { // insert into database System.out.println("Trying to add a new line"); ToDoEvent newEvt = new ToDoEvent(UUID.randomUUID().toString(), current.getName(), current.getPriority(), current.getDate()); eventDAO.insert(newEvt); } public void onClick$update() { if (box.getSelectedItem() != null) { // update database eventDAO.update((ToDoEvent) box.getSelectedItem().getValue()); } } public void onClick$delete() { if (box.getSelectedItem() != null) { eventDAO.delete((ToDoEvent) box.getSelectedItem().getValue()); } } }
you have the wrong signature:
public void onClick$add()
public void onClick$add(Event evt)
Shouldnt onClick$add have no parameters since it is calling on the field "(ToDoEvent) current". And I have the values of my textbox, intbox, and my datebox set to the relative value="@{win$composer.current.name}" or .priority or .date which ever is relevant. That should automatically update the "current" field to the corresponding data in the boxes which i should just be able to call on from this method. But as I said even if I put a System.out.println in on the first line of my onClick$add method nothing prints out to the console, making me believe that the onClick$add method isnt even being called.
Shouldnt onClick$add have no parameters
Hmmm....does your code work? No. Do I have 90 onClick handlers in 2 Eclipse projects that are deployed as a web app that work fine? Yes. Does the Javadoc for GenericForwardComposer (http://www.zkoss.org/javadoc/3.5.1/zk/org/zkoss/zk/ui/util/GenericForwardComposer.html) show a working example? Yes.
MyComposer.java public class MyComposer extends GenericForwardComposer { private Textbox mytextbox; private Window self; //embeded object, the supervised window "mywin" private Page page; //the ZK zuml page private Label mylabel; public void onChange$mytextbox(Event event) { mylabel.setValue("You just entered: "+ mytextbox.getValue()); } } test.zul <window id="mywin" apply="MyComposer"> <textbox id="mytextbox"/> <label id="mylabel"/> </window>
Is the method signature like my 90? Yes.
And I have the values of my textbox, intbox, and my datebox set to the relative value="@{win$composer.current.name}" or .priority or .date which ever is relevant. That should automatically update the "current" field to the corresponding data in the boxes which i should just be able to call on from this method.
Yes. That is databinding the fields and has nothing to do with your method invocation problems.
But as I said even if I put a System.out.println in on the first line of my onClick$add method nothing prints out to the console, making me believe that the onClick$add method isnt even being called.
The method ISN'T being called. That's because your signature is wrong. If you care to step down into the ZK source code, you'll see that when it's using reflection/introspection it's looking for a certain method signature. And that signature requires a single parameter of type Event or one of its subclasses.
My suggestion is that you take the 12 seconds that it will take to copy and paste that parameter to the signature and try it. If it doesn't work, then come back with questions. Don't question *before* you make an attempt or research the method signature in the code or Javadoc, it's rude.
Asked: 2009-10-15 16:16:29 +0800
Seen: 891 times
Last updated: Jun 11 '16