Pouplate dropdown values from datalist using ListofValueConstraint

cancel
Showing results for 
Search instead for 
Did you mean: 
sandhya_nair
Partner

Pouplate dropdown values from datalist using ListofValueConstraint

Hi,

I want to dynamically populate the dropdown values in alfresco share. I have created a datalist to store the dropdown values and created a class extending the ListOfValuesConstraint class and calling it from the model file. But there is no option to get the search service or node service to look for the datalist values from the custom class. I dont want to store the dropdown values in database since the maintenence also will be difficult. To add a new value later we may have to contact the DB team insert values on that table. Please see the code below.

Model File configuration
<constraint name="hrSmiley TonguerocesDropdownList"
type="com.poc.ddl.ProcessDropdownListConstraint">
<parameter name="allowedValues">
<list>
</list>
</parameter>
</constraint>


<property name="hrSmiley Tonguerocess">
<title>Process</title>
<type>d:text</type>
<mandatory>false</mandatory>
<index enabled="true">
<tokenised>TRUE</tokenised>
<facetable>false</facetable>
</index>
<constraints>
<constraint ref="hrSmiley TonguerocesDropdownList" />
</constraints>
</property>

share-config-custom.xml


<field id="hrSmiley Tonguerocess"
label-id="form.field.label.hr_process" set="hrDocSet">
<control
template="/org/alfresco/components/form/controls/selectone.ftl" />
</field>

public class ProcessDropdownListConstraint extends ListOfValuesConstraint{

private static ServiceRegistry serviceRegistry;

@Override
public void initialize() {


}

//I am unable to get the service registry object or  node Service or Search service here

@Override
public void setAllowedValues(List allowedValues) {
List<String> allowedValues1 = new ArrayList<String>();
allowedValues1.add("Payroll");
allowedValues1.add("Holiday and Absense");
allowedValues1.add("Hiring");
System.out.println("allowedValues1 "+allowedValues1);
super.setAllowedValues(allowedValues1);
}

Tried below code not working
ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
System.out.println("ctx "+ctx);

Also tried this way still getting application context as null.

public class ProcessDropdownListConstraint extends ListOfValuesConstraint implements ApplicationContextAware{


private static ServiceRegistry registry;
private static ApplicationContext applicationContext;


public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}

}

can anyone pelase help me on this?

Thanks in Advance,

Sandhya

2 Replies
angelborroy
Alfresco Employee

Re: Pouplate dropdown values from datalist using ListofValueConstraint

You should declare your ProcessDropdownListConstraint as an Spring bean an XML in order to inject ServiceRegistry.

You could find also interesting this approach:

GitHub - keensoft/alfresco-datalist-constraints: Use datalists to maintain Alfresco model constraint... 

This project allows the users to maintain the values in the datalists using Alfresco Share web interface.

Hyland Developer Evangelist
sandhya_nair
Partner

Re: Pouplate dropdown values from datalist using ListofValueConstraint

Thanks for the reply. I have added ProcessDropdownListConstraint class in a bean as below.


<bean id="ProcessDropdownListConstraint" class="com.util.ProcessDropdownListConstraint"
depends-on="repositoryEndBootstrapBean" lazy-init="default">
<property name="nodeService">
<ref bean="nodeService"/>
</property>
<property name="searchService">
<ref bean="searchService"/>
</property>
</bean>

I am getting the below error.

Caused by: org.springframework.beans.MethodInvocationException: Property 'allowedValues' threw exception; nested exception is org.alfresco.error.AlfrescoRuntimeException: 06150022 SOLR queries can not be executed while the repository is bootstrapping

Caused by: org.alfresco.error.AlfrescoRuntimeException: 06150022 SOLR queries can not be executed while the repository is bootstrapping