AnsweredAssumed Answered

Pouplate dropdown values from datalist using ListofValueConstraint

Question asked by sandhya.nair on Jul 15, 2019
Latest reply on Jul 15, 2019 by sandhya.nair

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="hr:procesDropdownList"
type="com.poc.ddl.ProcessDropdownListConstraint">
<parameter name="allowedValues">
<list>
</list>
</parameter>
</constraint>

 


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

 

share-config-custom.xml


<field id="hr:process"
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

Outcomes