cancel
Showing results for 
Search instead for 
Did you mean: 

Problem read all properties FacesContext must not be null

ersecchio
Champ in-the-making
Champ in-the-making
I implemented the following method to read all the properties of a model



AuthenticationUtils.startSession("admin", "MYPASSWORD");
FacesContext fc = FacesContext.getCurrentInstance();
ServiceRegistry services = Repository.getServiceRegistry(fc);
DictionaryService dd = services.getDictionaryService();
List<PropertyDefinition> res = new ArrayList<PropertyDefinition>();
      
QName typeQName = Repository.resolveToQName("sc:sc_article");
     
System.out.println("Type QNAME:" + typeQName);
   
   if (typeQName != null) {
          
      TypeDefinition typeDef = dd.getType(typeQName);
         System.out.println("Type Def:" + typeDef);
         if (typeDef != null) {
            Map<QName, org.alfresco.service.cmr.dictionary.PropertyDefinition> props = typeDef.getProperties();
            for (QName prop : props.keySet()) {
               System.out.println("Prop Name:" + prop);
               PropertyDefinition propDef = (PropertyDefinition) props.get(prop);
               System.out.println("Prop DEF:" + propDef);
               res.add(propDef);
            }
         }
      }


but when I do I get the following error

Exception in thread "main" java.lang.IllegalArgumentException: FacesContext must not be null
   at org.springframework.util.Assert.notNull(Assert.java:112)
   at org.springframework.web.jsf.FacesContextUtils.getWebApplicationContext(FacesContextUtils.java:50)
   at org.springframework.web.jsf.FacesContextUtils.getRequiredWebApplicationContext(FacesContextUtils.java:81)
   at org.alfresco.web.bean.repository.Repository.getServiceRegistry(Repository.java:584)
   at ritornaProprieta.main(ritornaProprieta.java:25)


could someone help me
:?:
3 REPLIES 3

patil
Champ on-the-rise
Champ on-the-rise
Hi,

You cannot get the FacesContext object in your main class.
If your environment is running in JSF then only you will be able to get FacesContext.

Thanks,
Patil
Cignex Technologies
Bangalore

ersecchio
Champ in-the-making
Champ in-the-making
hi,
I would like to create an object (ie: MYOBJ) that will enable me to return all the properties of a type, and use  this object in the Alfresco Javascript API,
how should I proceed to implement a java object which returns all the properties?

:cry:

wass
Champ in-the-making
Champ in-the-making
Hi Patil,

I'm trying to instantiate FacesContext not at main but into the class were i try to get my serviceRegistry.

i'm trying to do this:

package genericmodel.main;

import javax.faces.context.FacesContext;

import org.alfresco.service.ServiceRegistry;

public class GetServiceRegistry {
   private ServiceRegistry serviceRegistry;
   private FacesContext context= context = FacesContext.getCurrentInstance();
   
   public GetServiceRegistry(){
      serviceRegistry=org.alfresco.web.bean.repository.Repository.getServiceRegistry(context);
   }
   
   public ServiceRegistry getServiceRegistry() {
      return serviceRegistry;
   }
   
   public void setServiceRegistry(ServiceRegistry serviceRegistry) {
      this.serviceRegistry = serviceRegistry;
   }

   public FacesContext getContext() {
      return context;
   }

   public void setContext(FacesContext context) {
      this.context = context;
   }
}

my bean for the serviceRegistry is this:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

   <bean id="getServiceRegistry" class="genericmodel.main.GetServiceRegistry">
      <property name="serviceRegistry">
         <ref bean="ServiceRegistry"/>
      </property>
   </bean>
   
</beans>

but i'm getting my context null… how can i fix that?


thanks.