Page 1 of 1

Service Bean in core

Posted: Fri Mar 01, 2013 5:00 am
by julia
Hello,

I want to create the spring service bean in the core package. There is find all method to find my customerType entity. I want to find my entities by using this bean in my customerTypeUtil class that extends BroadleafEnumerationType because I don't want to add static customertype. I want to load from table.

I am trying to do like this. But I cannot inject the service bean in my customerTypeUtil. I got nullpointer exception. I have already defied service bean in the core's applicationContext.xml.

I would like to know that can I use spring service bean in the core package.


Thanks
Julia

Re: Service Bean in core

Posted: Tue Mar 05, 2013 5:30 pm
by phillipuniverse
You cannot do dependency injection in Broadleaf enumeration types as these are not spring managed beans.

If you want to get these types from the database, then you should use the @AdminPresentationDataDrivenEnumeration annotation. This will ensure that the dropdown is populated from a database table; the configuration here is pretty well documented in the Java class. You can use this in conjunction with @AdminPresentation to style how the field label should be displayed:

Code: Select all

@AdminPresentation(friendlyName="Customer Type")
@
AdminPresentationDataDrivenEnumeration()
protected 
String customerType;
 

Re: Service Bean in core

Posted: Wed Mar 13, 2013 12:08 am
by julia
Hello,
Thank for ur reply.

Yes, I have tried what u said. I create new entity(dynaCustomerTypeImpl) to load from database. I use this class in the customerType entity. This coding is in the customerType entity.

Code: Select all

@AdminPresentation(friendlyName = "customer Type")
@AdminPresentationDataDrivenEnumeration(optionListEntity = dynaCustomerTypeImpl.class, optionValueFieldName = "name", optionDisplayFieldName = "customer Type")
   private String type;

I got null pointer exception in the buildDataDrivenList method of Metadata class. Actually I found that the exception occurred from the looping which iterates the optionalFilterParams.

Do I need to use optionFilterParams to load entity instances? I think, I don't need it because I want to find all of entity instances from database. Is there any wrong in my coding?


Thanks,
Julia