[Building Sakai] getting DAO instance

Aaron Zeckoski aaronz at vt.edu
Sat Apr 11 01:05:30 PDT 2009


No problem. Glad to hear it is resolved.
-AZ

On Sat, Apr 11, 2009 at 8:54 AM, Ketan Nale <ketan_nale at yahoo.com> wrote:
> Thanks dear,
> After all ,it is in function.
> Everything is working fine.
>
> Thanks for your great support,
> ketan
>
>
> --- On Fri, 10/4/09, Aaron Zeckoski <aaronz at vt.edu> wrote:
>
> From: Aaron Zeckoski <aaronz at vt.edu>
> Subject: Re: [Building Sakai] getting DAO instance
> To: "KetanNale" <ketan_nale at yahoo.com>
> Cc: sakai-dev at collab.sakaiproject.org
> Date: Friday, 10 April, 2009, 8:18 PM
>
> This looks like the same issue I responded to earlier to me. It is
> saying your dependency injection is not setup correctly. Here is the
> previous response for reference. Like I said before, you really should
> not be using the Impl and should be using the interface instead,
> otherwise it will attempt to cast the proxy to the impl and will
> definitely fail:
>
> ===== previous message ======
> OK, here is the problem in the code. You are not using dependency
> injection to get the service (or dao in your case) into your tool
> code. So, this code in PersonTool is not going to work for a few
> reasons:
> if(personManager==null)
> {
>        System.out.println("in if(personManager==null) check");
>        personManager = new PersonManagerImpl();
>        if(personManager==null)
>        {
>                System.out.println("in if(personManager==null) check again");
>        }
>        else
>        {
>                personManager.savePerson(person);
>        }
> }
>
> 1) It will never do a save unless the personManager is null (which it
> won't be once you fix the DI)
> 2) You are creating the DAO (PersonManagerImpl) using new when you
> need to actually use the one which was created by spring (because of
> your components.xml file)
> 3) an object which is created using a constructor can never be null so
> the check for null after creating the object is not needed and is
> confusing
> 4) This is not the problem here but you should no use the IMPL in this
> class, use the interface instead
>
> To fix the issue, you would change the code above to:
> personManager.savePerson(person);
>
> And in your faces-config you would need to add something like this:
> <managed-bean>
> ....
>
> <managed-bean-class>org.sakaiproject.tool.person.PersonTool</managed-bean-class>
> ....
>                <managed-property>
>                        <description>personManager</description>
>                        <property-name>personManager</property-name>
>
> <value>#{Components["org.sakaiproject.api.app.person.PersonManager"]}</value>
>                </managed-property>
> </managed-bean>
>
> That will inject the PersonManager into the tool via the setter for
> PersonManager.
> -AZ
>
>
>
> On Fri, Apr 10, 2009 at 2:58 PM, KetanNale <ketan_nale at yahoo.com> wrote:
>>
>> I am getting following stacktrace while calling any method of my AapTool
>> from
>> page
>>
>> PersonManagerImpl is my DAOImpl
>>
>> 2009-04-10 19:03:41,281 ERROR http-8080-Processor24
>> com.sun.faces.application.ApplicationImpl - Managedbean PersonTool could
>> not be created Can't instantiate class:
>> 'org.sakaiproject.component.app.person.PersonManagerImpl at 248f34'.
>> javax.faces.FacesException: Can't instantiate class:
>> 'org.sakaiproject.component.app.person.PersonManagerImpl at 248f34'.
>>        at
>>
>> com.sun.faces.config.ManagedBeanFactory.getConvertedValueConsideringPrimitives(ManagedBeanFactory.java:869)
>>        at
>>
>> com.sun.faces.config.ManagedBeanFactory.setPropertiesIntoBean(ManagedBeanFactory.java:555)
>>        at
>>
>> com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:233)
>>        at
>>
>> com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:256)
>>        at
>>
>> com.sun.faces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:78)
>>        at
>>
>> org.sakaiproject.jsf.app.SakaiVariableResolver.resolveVariable(SakaiVariableResolver.java:76)
>>        at com.sun.faces.el.impl.NamedValue.evaluate(NamedValue.java:125)
>>        at
>>
>> com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:243)
>>        at
>> com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:173)
>>        at
>> com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:154)
>>        at
>> com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:123)
>>        at
>>
>> com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
>>        at javax.faces.component.UICommand.broadcast(UICommand.java:312)
>>        at
>> javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
>>        at
>> javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
>>        at
>>
>> com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
>>        at
>> com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
>>        at
>> com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
>>        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>>        at
>> org.sakaiproject.util.RequestFilter.doFilter(RequestFilter.java:561)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>>        at
>>
>> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
>>        at
>>
>> org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461)
>>        at
>>
>> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:399)
>>        at
>>
>> org.apache.catalina.core..ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
>>        at org.sakaiproject.jsf.util.JsfTool.dispatch(JsfTool.java:221)
>>        at org.sakaiproject.jsf.util..JsfTool.doPost(JsfTool.java:256)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>>        at
>> org.sakaiproject.util.RequestFilter.doFilter(RequestFilter.java:561)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>>        at
>>
>> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
>>        at
>>
>> org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461)
>>        at
>>
>> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:364)
>>        at
>>
>> org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
>>        at
>>
>> org.sakaiproject..tool.impl.ActiveToolComponent$MyActiveTool.forward(ActiveToolComponent.java:475)
>>        at
>>
>> org.sakaiproject.portal.charon.SkinnableCharonPortal.forwardTool(SkinnableCharonPortal.java:1250)
>>        at
>>
>> org.sakaiproject.portal.charon.handlers.ToolHandler.doTool(ToolHandler.java:188)
>>        at
>>
>> org.sakaiproject.portal.charon.handlers.ToolHandler..doGet(ToolHandler.java:93)
>>        at
>>
>> org.sakaiproject.portal.charon.handlers.ToolHandler.doPost(ToolHandler.java:70)
>>        at
>>
>> org.sakaiproject.portal.charon.SkinnableCharonPortal.doPost(SkinnableCharonPortal.java:1093)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
>>        at javax.servlet.http.HttpServlet.service(HttpServlet..java:729)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
>>        at
>>
>> org.apache.catalina.core..ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>>        at
>> org.sakaiproject.util.RequestFilter.doFilter(RequestFilter.java:613)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
>>        at
>>
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain..java:188)
>>        at
>>
>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
>>        at
>>
>> org.apache.catalina..core.StandardContextValve.invoke(StandardContextValve.java:172)
>>        at
>>
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>>        at
>>
>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
>>        at
>>
>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
>>        at
>>
>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
>>        at
>> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
>>        at
>>
>> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
>>
>>        at
>>
>> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
>>        at
>>
>> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
>>        at
>>
>> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
>>        at java.lang.Thread.run(Thread.java:595)
>> 2009-04-10 19:03:41,281 ERROR http-8080-Processor24
>> com.sun..faces.lifecycle.InvokeApplicationPhase - #{PersonTool.processAdd}
>> : javax.faces.el.EvaluationException: javax.faces.FacesException:
>> javax.faces.FacesException: Can't instantiate class: 'org.s
>> akaiproject.component.app.person.PersonManagerImpl at 248f34'.
>> javax.faces.FacesException: #{PersonTool.processAdd}:
>> javax.faces.el.EvaluationException: javax.faces.FacesException: javax.f
>> aces.FacesException: Can't instantiate class:
>> 'org.sakaiproject.component.app.person.PersonManagerImpl at 248f34'.
>>        at
>>
>> com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
>>        at javax.faces.component.UICommand.broadcast(UICommand.java:312)
>>        at
>> javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
>>        at
>> javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
>> --
>> View this message in context:
>> http://www.nabble.com/getting-DAO-instance-tp22988403p22988403.html
>> Sent from the Sakai - Development mailing list archive at Nabble.com.
>>
>> _______________________________________________
>> sakai-dev mailing list
>> sakai-dev at collab.sakaiproject.org
>> http://collab.sakaiproject.org/mailman/listinfo/sakai-dev
>>
>> TO UNSUBSCRIBE: send email to
>> sakai-dev-unsubscribe at collab.sakaiproject.org with a subject of
>> "unsubscribe"
>>
>
>
>
> --
> Aaron Zeckoski (aaronz at vt.edu)
> Senior Research Engineer - CARET - Cambridge University
> [http://bugs.sakaiproject.org/confluence/display/~aaronz/]
> Sakai Fellow - [http://aaronz-sakai.blogspot.com/]
>
> ________________________________
> Add more friends to your messenger and enjoy! Invite them now.



-- 
Aaron Zeckoski (aaronz at vt.edu)
Senior Research Engineer - CARET - Cambridge University
[http://bugs.sakaiproject.org/confluence/display/~aaronz/]
Sakai Fellow - [http://aaronz-sakai.blogspot.com/]


More information about the sakai-dev mailing list