AnsweredAssumed Answered

When extending the ListOfValuesConstraint with an id,name structure, how do you modify the search element so that you can search using the name rather than the id?

Question asked by adamparker on May 2, 2017
Latest reply on May 2, 2017 by afaust

Hi All,


I have successfuly created a dynamic list constraint by extending the ListOfValuesConstraint.

The database table (custom_entities) has two columns (id,name) as follows:
id, name
1, EntityA
2, EntityB
3, EntityC


The property stores the id value (1), but share shows the name label (EntityA) throughout.  This is how you would expect it to work.



However, I am not sure how to make the search work.

For example the following search will find all Entities with id 1:


However I want a way to be able to use the name field, like so:


Since the id is the only value stored clearly this won't work out of the box.


Can somebody please provide some suggestions on a potential way forward with this?

I want to avoid using the name field as reference, which would have been the easy way out.


Best Regards,




// ListOfEntitiesConstraint
public class ListOfEntitiesConstraint extends ListOfValuesConstraint implements Serializable {

    private static final long serialVersionUID = 1;
    private List<String> allowedLabels;

    public void setAllowedValues(List allowedValues) {

    public void setCaseSensitive(boolean caseSensitive) {

    public void initialize() {

    public List<String> getAllowedValues() {
        return super.getAllowedValues();

    public List<String> getAllowedLabels() {
        return this.allowedLabels;

    public void setAllowedLabels(List<String> allowedLabels) {
        this.allowedLabels = allowedLabels;

    public List<SelectItem> getSelectItemList() {
        List<SelectItem> result = new ArrayList<SelectItem>(this.getAllowedValues().size());
        for (int i = 0; i < this.getAllowedValues().size(); i++) {
            result.add(new SelectItem((Object) this.getAllowedValues().get(i), this.allowedLabels.get(i)));
        return result;

    public String getDisplayLabel(String constraintAllowableValue, MessageLookup messageLookup) {
        if (!super.getAllowedValues().contains(constraintAllowableValue))
            return null;
        String message = this.getAllowedLabels().get(super.getAllowedValues().indexOf(constraintAllowableValue));
        return message == null ? constraintAllowableValue : message;
        //return super.getDisplayLabel(constraintAllowableValue, messageLookup);

    protected void loadDB() {

        String driverName = "org.postgresql.Driver";
        String serverName = "alfresco.meab.local";
        String mydatabase = "alfresco";
        String username = "postgres";
        String password = "password";

        List<String> av = new ArrayList<String>();
        List<String> al = new ArrayList<String>();

        try {
            Connection connection = null;
            String url = "jdbc:postgresql://" + serverName + "/" + mydatabase;
            connection = DriverManager.getConnection(url, username, password);
            Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("select id, name from custom_entities order by name ASC");
            while ( {
        } catch (Exception e) {



<!-- Relevant parts of model -->
    <constraint name="ukl:entityList_constraint" type="com.acme.cmspoc2.demoamp.ListOfEntitiesConstraint">
        <parameter name="allowedValues">
        <parameter name="caseSensitive">
<type name="ukl:doc">
            <title>General Document</title>
                <property name="ukl:entity">
                        <constraint ref="ukl:entityList_constraint" />