AnsweredAssumed Answered

retrieving a bean instance

Question asked by tfaudot on Aug 12, 2008
Latest reply on Aug 14, 2008 by jbarmash
I would like the "paste all" action to be visible only when there is an item in the clipboard.

Hence I have created an evaluator :

package fr.edugeo.alfresco.evaluators;

import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.web.action.ActionEvaluator;
import org.alfresco.web.bean.clipboard.ClipboardBean;
import org.alfresco.web.bean.repository.Node;

public class ClipboardPasteAllActionEvaluator implements ActionEvaluator {
   
   public boolean evaluate(Node node) {
      //on vérifie qu'il y a quelque chose dans le presse papier
      ClipboardBean bean = (ClipboardBean)ApplicationContextHelper.getApplicationContext().getBean("ClipboardBean");
      if(bean.getItems().size()==0){
         return false;
      }
      return true;
   }
}

But it seems that whenever I enter this part:
ClipboardBean bean = (ClipboardBean)ApplicationContextHelper.getApplicationContext().getBean("ClipboardBean");

I get an exception :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'workflowScheduler' defined in class path resource [alfresco/bootstrap-context.xml]: Cannot resolve reference to bean 'jbpm_template' while setting bean property 'JBPMTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_template' defined in class path resource [alfresco/workflow-context.xml]: Cannot resolve reference to bean 'jbpm_configuration' while setting constructor argument with index 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_template' defined in class path resource [alfresco/workflow-context.xml]: Cannot resolve reference to bean 'jbpm_configuration' while setting constructor argument with index 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jbpm_configuration' defined in class path resource [alfresco/workflow-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
Caused by: java.lang.IllegalArgumentException: a beanFactoryReference already exists for key jbpm_configuration
   at org.springmodules.workflow.jbpm31.JbpmFactoryLocator.addToMap(JbpmFactoryLocator.java:108)
   at org.springmodules.workflow.jbpm31.JbpmFactoryLocator.setBeanFactory(JbpmFactoryLocator.java:76)
   at org.alfresco.repo.workflow.jbpm.AlfrescoJbpmConfigurationFactoryBean.setBeanFactory(AlfrescoJbpmConfigurationFactoryBean.java:68)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1076)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:245)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:124)
   at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:316)
   at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:91)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:745)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:683)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:388)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:245)
   at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:124)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1019)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:809)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:425)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:236)
   at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:701)
   at org.springframework.context.support.AbstractApplicationContext.registerListeners(AbstractApplicationContext.java:519)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:343)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
   at org.alfresco.util.ApplicationContextHelper.getApplicationContext(ApplicationContextHelper.java:55)
   at fr.edugeo.alfresco.evaluators.ClipboardPasteAllActionEvaluator.evaluate(ClipboardPasteAllActionEvaluator.java:25)
   at org.alfresco.web.ui.repo.component.evaluator.ActionInstanceEvaluator.evaluate(ActionInstanceEvaluator.java:57)
   at org.alfresco.web.ui.common.component.evaluator.BaseEvaluator.getRendersChildren(BaseEvaluator.java:54)
   at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:413)
   at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChildren(RendererUtils.java:400)
   at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:417)
   at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChildren(RendererUtils.java:400)
   at org.apache.myfaces.shared_impl.renderkit.html.HtmlGroupRendererBase.encodeEnd(HtmlGroupRendererBase.java:78)
   at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
   at org.alfresco.web.ui.common.Utils.encodeRecursive(Utils.java:427)
   at org.alfresco.web.ui.repo.component.UIActions.encodeChildren(UIActions.java:247)
   at javax.faces.webapp.UIComponentTag.encodeChildren(UIComponentTag.java:483)
   at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:364)
   at org.apache.jsp.jsp.browse.browse_jsp._jspx_meth_r_005factions_005f1(browse_jsp.java:1768)
   at org.apache.jsp.jsp.browse.browse_jsp._jspx_meth_a_005fmenu_005f1(browse_jsp.java:1743)
   at org.apache.jsp.jsp.browse.browse_jsp._jspx_meth_a_005fbooleanEvaluator_005f6(browse_jsp.java:1710)
   at org.apache.jsp.jsp.browse.browse_jsp._jspx_meth_a_005fpanel_005f0(browse_jsp.java:1368)
   at org.apache.jsp.jsp.browse.browse_jsp._jspService(browse_jsp.java:590)
   at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
   at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
   at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:691)
   at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:469)
   at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:403)
   at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
   at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
   at org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
   at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
   at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:81)
   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:210)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   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:151)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
   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:685)
   at java.lang.Thread.run(Thread.java:595)

What am I doing wrong?
Thanks!

Outcomes