09-11-2007 04:19 AM
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();
}
}
09-17-2007 08:01 AM
01-16-2008 06:44 PM
f the first context initialization didn't use ApplicationContextHelper, then you can't use it either.
03-13-2008 01:35 PM
03-31-2008 08:37 AM
The application context is being initialized somewhere else - this depends on how you are starting the application in the first place. You cannot start it twice and if the first context initialization didn't use ApplicationContextHelper, then you can't use it either.I've got the same problem. And I didn't understand how to sovle it too :cry: For me it's very strange that Alfresco platform has ApplicationContextHelper class which doesn't return application context :?
06-23-2008 05:38 AM
Create a bean that is ApplicationContextAware and use that to push the context (not a specific bean) onto a static member. You can then retrieve it statically from the constraint implementation at runtime.
public class MyApplicationContextHelper implements ApplicationContextAware {
private static ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext arg0)
throws BeansException {
applicationContext = arg0;
}
public static ApplicationContext getApplicationContext()
{
return applicationContext;
}
public static Object getBean(String beanName)
{
if(beanName==null||beanName.trim().length()==0)
{
return null;
}
else{
return applicationContext.getBean(beanName);
}
}
}
Spring creates an instance of this bean, and then I can access the ApplicationContext in any class doing:Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.