5 Replies Latest reply on Jan 8, 2009 9:08 PM by cpopetz

    Wicket database-backed page

    dhcinc

      Well I've moved on to trying to couple my Wicket sample page with the database via Seam using the Wicket Booking example as a guide. The application is failing because it cannot find an instance of fooList.


      Here is the stack dump


      WicketMessage: Method onLinkClicked of interface org.apache.wicket.markup.html.link.ILinkListener targeted at component [MarkupContainer [Component id = show-foo-entity-link, page = com.dhc.wicket.web.HomePage, path = 0:show-foo-entity-link.HomePage$1, isVisible = true, isVersioned = true]] threw an exception
      
      Root cause:
      
      javax.naming.NameNotFoundException: wicket not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
      at javax.naming.InitialContext.lookup(InitialContext.java:392)
      at org.jboss.seam.Component.instantiateSessionBean(Component.java:1367)
      at org.jboss.seam.Component.instantiate(Component.java:1331)
      at org.jboss.seam.Component.newInstance(Component.java:2084)
      at org.jboss.seam.Component.getInstance(Component.java:1988)
      at org.jboss.seam.Component.getInstance(Component.java:1950)
      at org.jboss.seam.Component.getInstance(Component.java:1944)
      at org.jboss.seam.wicket.WicketComponent.getInstanceInAllNamespaces(WicketComponent.java:475)
      at org.jboss.seam.wicket.WicketComponent.getValue(WicketComponent.java:442)
      at org.jboss.seam.wicket.WicketComponent.inject(WicketComponent.java:317)
      at org.jboss.seam.wicket.ioc.BijectionInterceptor.beforeInvoke(BijectionInterceptor.java:21)
      at org.jboss.seam.wicket.ioc.WicketHandler.doBeforeInvoke(WicketHandler.java:66)
      at org.jboss.seam.wicket.ioc.WicketHandler.beforeInvoke(WicketHandler.java:52)
      at com.dhc.wicket.web.ShowFooList.<init>(ShowFooList.java:26)
      at com.dhc.wicket.web.HomePage$1.onClick100(HomePage.java:14)
      at com.dhc.wicket.web.HomePage$1.onClick(HomePage.java)
      at org.apache.wicket.markup.html.link.Link.onLinkClicked(Link.java:214)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183)
      at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
      at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
      at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
      at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
      at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
      at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
      at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)
      at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194)
      at org.jboss.seam.web.WicketFilter$1.process(WicketFilter.java:128)
      at org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:53)
      at org.jboss.seam.web.WicketFilter.doFilter(WicketFilter.java:74)
      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      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:230)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      at java.lang.Thread.run(Thread.java:619)
      
      Complete stack:
      
      org.apache.wicket.WicketRuntimeException: Method onLinkClicked of interface org.apache.wicket.markup.html.link.ILinkListener targeted at component [MarkupContainer [Component id = show-foo-entity-link, page = com.dhc.wicket.web.HomePage, path = 0:show-foo-entity-link.HomePage$1, isVisible = true, isVersioned = true]] threw an exception
      at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:194)
      at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
      at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
      at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
      at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
      at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
      at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
      at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)
      
      java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183)
      at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
      at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
      at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
      at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
      at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
      at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
      at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)
      
      java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: org.jboss.seam.InstantiationException: Could not instantiate Seam component: fooList
      at com.dhc.wicket.web.HomePage$1.onClick(HomePage.java)
      at org.apache.wicket.markup.html.link.Link.onLinkClicked(Link.java:214)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183)
      at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
      at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
      at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
      at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
      at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
      at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
      at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)
      
      java.lang.RuntimeException: java.lang.RuntimeException: org.jboss.seam.InstantiationException: Could not instantiate Seam component: fooList
      at com.dhc.wicket.web.ShowFooList.<init>(ShowFooList.java:28)
      at com.dhc.wicket.web.HomePage$1.onClick100(HomePage.java:14)
      at com.dhc.wicket.web.HomePage$1.onClick(HomePage.java)
      at org.apache.wicket.markup.html.link.Link.onLinkClicked(Link.java:214)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183)
      at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
      at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
      at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
      at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
      at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
      at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
      at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)
      
      java.lang.RuntimeException: org.jboss.seam.InstantiationException: Could not instantiate Seam component: fooList
      at org.jboss.seam.wicket.ioc.BijectionInterceptor.beforeInvoke(BijectionInterceptor.java:26)
      at org.jboss.seam.wicket.ioc.WicketHandler.doBeforeInvoke(WicketHandler.java:66)
      at org.jboss.seam.wicket.ioc.WicketHandler.beforeInvoke(WicketHandler.java:52)
      at com.dhc.wicket.web.ShowFooList.<init>(ShowFooList.java:26)
      at com.dhc.wicket.web.HomePage$1.onClick100(HomePage.java:14)
      at com.dhc.wicket.web.HomePage$1.onClick(HomePage.java)
      at org.apache.wicket.markup.html.link.Link.onLinkClicked(Link.java:214)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183)
      at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
      at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
      at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
      at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
      at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
      at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
      at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)
      
      org.jboss.seam.InstantiationException: Could not instantiate Seam component: fooList
      at org.jboss.seam.Component.newInstance(Component.java:2106)
      at org.jboss.seam.Component.getInstance(Component.java:1988)
      at org.jboss.seam.Component.getInstance(Component.java:1950)
      at org.jboss.seam.Component.getInstance(Component.java:1944)
      at org.jboss.seam.wicket.WicketComponent.getInstanceInAllNamespaces(WicketComponent.java:475)
      at org.jboss.seam.wicket.WicketComponent.getValue(WicketComponent.java:442)
      at org.jboss.seam.wicket.WicketComponent.inject(WicketComponent.java:317)
      at org.jboss.seam.wicket.ioc.BijectionInterceptor.beforeInvoke(BijectionInterceptor.java:21)
      at org.jboss.seam.wicket.ioc.WicketHandler.doBeforeInvoke(WicketHandler.java:66)
      at org.jboss.seam.wicket.ioc.WicketHandler.beforeInvoke(WicketHandler.java:52)
      at com.dhc.wicket.web.ShowFooList.<init>(ShowFooList.java:26)
      at com.dhc.wicket.web.HomePage$1.onClick100(HomePage.java:14)
      at com.dhc.wicket.web.HomePage$1.onClick(HomePage.java)
      at org.apache.wicket.markup.html.link.Link.onLinkClicked(Link.java:214)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183)
      at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
      at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91)
      at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166)
      at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243)
      at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1331)
      at org.apache.wicket.RequestCycle.request(RequestCycle.java:493)
      at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:363)



      Ths is my Foo class:


      package com.dhc.wicket;
      
      import java.io.Serializable;
      import javax.persistence.Entity;
      import javax.persistence.GeneratedValue;
      import javax.persistence.Id;
      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      
      @Entity(name="Foo")
      public class Foo implements Serializable {
          private Long id;
          private String firstName;
          private String lastName;
      
          public Foo() { }
      
          public Foo(String firstName, String lastName) {
              this.firstName = firstName;
              this.lastName = lastName;
          }
      
          @Id @GeneratedValue
          public Long getId() {
              return this.id;
          }
      
          public void setId(Long id) {
              this.id = id;
          }
      
          @NotNull(message="First name is required")
          @Length(min=1, max=255, message="First name must be 1 to 255 characters")
          public String getFirstName() {
              return this.firstName;
          }
      
          public void setFirstName(String firstName) {
              this.firstName = firstName;
          }
      
          @NotNull(message="Last name is requried")
          @Length(min=3, max=255, message="Last name must be 3 to 255 characters")
          public String getLastName() {
              return this.lastName;
          }
      
          public void setLastName(String lastName) {
              this.lastName = lastName;
          }
      
          @Override
          public String toString() {
              return("Foo("+firstName+", "+lastName+")");
          }
      }
      



      This is the FooList interface:


      package com.dhc.wicket;
      
      import java.util.List;
      import javax.ejb.Local;
      
      @Local
      public interface FooList {
          public List<Foo> getList();
          public void destroy();
      }
      



      This is the FooList action:


      package com.dhc.wicket;
      
      import java.io.Serializable;
      import java.util.List;
      import javax.ejb.Remove;
      import javax.ejb.Stateful;
      import javax.persistence.EntityManager;
      import javax.persistence.PersistenceContext;
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Destroy;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Out;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.log.Log;
      
      @Stateful
      @Scope(ScopeType.SESSION)
      @Name("fooList")
      public class FooListAction implements FooList, Serializable {
          private static final long serialVersionUID = 1L;
          
          @PersistenceContext
          private EntityManager em;
      
          @Logger
          private Log log;
      
          @Out
          private List<Foo> foos;
      
          public FooListAction() { }
          
          @Override
          public List<Foo> getList() {
              log.debug("getFooEntities()");
              foos = em.createQuery("select f from Foo").getResultList();
              log.debug("found "+foos.size()+" entities");
              return foos;
          }
      
          @Override @Remove @Destroy
          public void destroy() {}
      
      }
      



      This is the wicket page backing class:


      package com.dhc.wicket.web;
      
      import com.dhc.wicket.Foo;
      
      import com.dhc.wicket.FooList;
      import java.util.Iterator;
      
      import java.util.List;
      import org.apache.wicket.PageParameters;
      import org.apache.wicket.markup.html.WebPage;
      import org.apache.wicket.markup.html.basic.Label;
      import org.apache.wicket.markup.html.link.Link;
      import org.apache.wicket.markup.repeater.Item;
      import org.apache.wicket.markup.repeater.data.DataView;
      import org.jboss.seam.annotations.In;
      
      
      public final class ShowFooList extends WebPage {
          @In(create = true)
          private FooList fooList;
      
          private List<Foo> foos;
          private DataView fooDataView;
      
          public ShowFooList() {
              super();
              init();
          }
          
          public ShowFooList(final PageParameters params) {
              super(params);
              init();
          }
      
          private void init() {
              foos = fooList.getList();
      
              fooDataView = new DataView("fooDataView", new SimpleDataProvider() {
                  @Override
                  public Iterator iterator(int from, int count) {
                      return foos.subList(from, from+count).iterator();
                  }
      
                  @Override
                  public int size() {
                      return foos.size();
                  }
              }) {
                  @Override
                  protected void populateItem(Item item) {
                      final Foo foo = (Foo)item.getModelObject();
                      item.add(new Label("firstname", foo.getFirstName()));
                      item.add(new Label("lastname", foo.getLastName()));
                  }
              };
      
              fooDataView.setItemsPerPage(10);
              fooDataView.setOutputMarkupId(true);
              add(fooDataView);
      
              add(new Link("home-page-link") {
                  public void onClick() {
                      setResponsePage(new HomePage());
                  }
              });
          }
      }
      



      The FooList, FooListAction and Foo classes are not instrumented. Everything else is. All classes end up in WEB-INF/classes.


      Any ideas why the fooList component is not being found? Also any comments on the general approach being used (or that should be used) for data-coupled wicket web pages would be welcomed.


      Thanks
      -david-


      p.s. While the booking example is very complete, it is very complicated for someone learning how to couple wicket and seam. Perhaps a less complex example could be offered that shows a single data-backed web page implementation?

        • 1. Re: Wicket database-backed page
          cpopetz


          javax.naming.NameNotFoundException: wicket not bound
          at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
          at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
          at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
          at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
          at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
          at javax.naming.InitialContext.lookup(InitialContext.java:392)
          at org.jboss.seam.Component.instantiateSessionBean(Component.java:1367)


          That indicates that jndi can't find the session bean for fooList.  What is your jndiPattern in components.xml, and what is the name of your deployment, and what J2EE container are you using?

          • 2. Re: Wicket database-backed page
            dhcinc

            JBoss 4.2.3.GA


            components.xml


            <?xml version="1.0" encoding="UTF-8"?>
            <components xmlns="http://jboss.com/products/seam/components"
                        xmlns:core="http://jboss.com/products/seam/core"
                        xmlns:persistence="http://jboss.com/products/seam/persistence"
                        xmlns:drools="http://jboss.com/products/seam/drools"
                        xmlns:bpm="http://jboss.com/products/seam/bpm"
                        xmlns:security="http://jboss.com/products/seam/security"
                        xmlns:mail="http://jboss.com/products/seam/mail"
                        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:wicket="http://jboss.com/products/seam/wicket"
                        xsi:schemaLocation=
                            "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd
                             http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd
                             http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                             http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                             http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                             http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.1.xsd
                             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">
            
               <core:init debug="@debug@" jndi-pattern="@jndiPattern@"/>
            
               <component name="org.jboss.seam.debug.hotDeployFilter">
                  <property name="urlPattern">*.seam</property>
               </component>
            
               <core:manager concurrent-request-timeout="500"
                             conversation-timeout="120000"
                             conversation-id-parameter="cid"
                             parent-conversation-id-parameter="pid"/>
            
               <persistence:managed-persistence-context name="entityManager"
                                                 auto-create="true"
                                      entity-manager-factory="#{wicketEntityManagerFactory}"/>
            
               <persistence:entity-manager-factory name="wicketEntityManagerFactory"
                                  persistence-unit-name="wicket"/>
            
               <drools:rule-base name="securityRules">
                  <drools:rule-files><value>/security.drl</value></drools:rule-files>
               </drools:rule-base>
            
               <security:rule-based-permission-resolver security-rules="#{securityRules}"/>
            
               <security:identity authenticate-method="#{authenticator.authenticate}" remember-me="true"/>
            
               <event type="org.jboss.seam.security.notLoggedIn">
                  <action execute="#{redirect.captureCurrentView}"/>
               </event>
               <event type="org.jboss.seam.security.loginSuccessful">
                  <action execute="#{redirect.returnToCapturedView}"/>
               </event>
            
               <mail:mail-session host="localhost" port="2525" username="test" password="test" />
            
               <!-- For use with jBPM pageflow or process management -->
               <!--
               <bpm:jbpm>
                  <bpm:process-definitions></bpm:process-definitions>
                  <bpm:pageflow-definitions></bpm:pageflow-definitions>
               </bpm:jbpm>
               -->
            
               <!-- Wicket support -->
               <wicket:web-application application-class="com.dhc.wicket.web.WicketApplication" />
            
            </components>
            



            components-dev.properties


            # These properties are used to replace Ant-style tokens in the component descriptor (components.xml) at runtime.
            jndiPattern=wicket/#{ejbName}/local
            debug=true
            



            The deployment name is 'wicket'.


            -david-

            • 3. Re: Wicket database-backed page
              cpopetz

              Are you deploying as an ear?  You can't deploy ejbs (SFSB or SLSB) in a war deployment.

              • 4. Re: Wicket database-backed page
                dhcinc

                Doh! That sounds like the right answer.


                Does the rest of the code look reasonable? i.e. Am I doing it right?


                -david-

                • 5. Re: Wicket database-backed page
                  cpopetz

                  From my cursory inspection, yes.  But you have experience with how much that's worth :)