AnsweredAssumed Answered

Acquiring ApplicationContext inside ListOfValuesConstraint

Question asked by robertito on Sep 11, 2007
Latest reply on Jun 23, 2008 by enrico_it
Hi!

I was trying to add a constraint type programmatically, by extending it from ListOfValuesConstraint. I want to fill a listbox with values extracted from the alfresco repository (defined in a particular space), but when I try to acquire the ApplicationContext, it looks like it tries to initialize the Repository again, and therefore throws an exception. Does anybody know if there is any way to solve this?

Thank you very much!
Robert

The piece of code that performs this, and the exception follow:

The variable allowedValues is filled with the values to display in the list box.

public List<String> getAllowedValues() {
      
  ApplicationContext context =  ApplicationContextHelper.getApplicationContext(); // EXCEPTION!!!
         
  Repository repository = (Repository) context.getBean("JCR.Repository");
         
  Session session = null;
         
  try {

    session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

    Node root = session.getRootNode();
    Node node = root.getNode("app:company_home/cm:Applications/cm:Values");

    allowedValues = new ArrayList<String>();
            
    // Fill allowedValues with the names of the nodes…
   
    return allowedValues;
            
  } catch (Exception e) {
    // …handle exceptions…
  }
  finally {
    session.logout();
  }
}

Exception:

18:21:37,584 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/alfresco].[jsp]] Servlet.service() for servlet jsp threw exception
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.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68)
at lu.intrasoft.alfresco.tools.constraint.ListOfValuesFromRepositoryConstraint.getAllowedValues(ListOfValuesFromRepositoryConstraint.java:101)
at org.alfresco.web.bean.generator.TextFieldGenerator.createComponent(TextFieldGenerator.java:141)
at org.alfresco.web.bean.generator.BaseComponentGenerator.generateAndAdd(BaseComponentGenerator.java:87)
at org.alfresco.web.ui.repo.component.property.UIProperty.generateControl(UIProperty.java:185)
at org.alfresco.web.ui.repo.component.property.UIProperty.generateItem(UIProperty.java:126)
at org.alfresco.web.ui.repo.component.property.PropertySheetItem.encodeBegin(PropertySheetItem.java:74)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:412)

at java.lang.Thread.run(Thread.java:595)

Outcomes