1

I have a task in which I have to present a drop down with client names while uploading a document of a particular type. The names of the client are tied to folders in a given site.

For e.g. Let say I have a site XYZ in alfresco and I have 10 folder with names Client 1 to Client 10 all on the same level, now while uploading the doc the client name field should be populated by the names of the folder present in the site.

I have created a custom java class that will fetch the folder names and place a constraint on the client name in the custom-model.xml file. I was able to show the hard-coded data as a dropdown but now I want the data to be fetched dynamically.

As I am new to alfresco I don't have enough idea how to get it done. I am trying to use Alfresco public java api and CMIS but not able to get anywhere.

Any help on this will be extremely helpful.

Here is the code.

model.xml

    <!-- For client name -->
    <constraint name="ev:clientNames" type="com.eisenvault.repo.dictionary.constraint.ClientNameConstraint">
         <parameter name="allowedValues">
            <list>
                <value></value>
                 <!-- Will be empty -->
            </list>
         </parameter>
    </constraint>

ClientNameConstraint.java

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class ClientNameConstraint extends ListOfValuesConstraint implements Serializable {
/**
 * 
 */
private static final long serialVersionUID = 1L;

Log log = LogFactory.getLog(ClientNameConstraint.class);

private List<String> allowedValues;
protected boolean caseSensitive;
protected boolean sorted;

public ClientNameConstraint(){
    caseSensitive = true;
    sorted = false;
    allowedValues = Collections.emptyList();
}

@Override
public List<String> getAllowedValues() {
    allowedValues = Arrays.asList("Client1", "Client2", "Client3", "Client4", "Client5", "Client6");
    Collections.sort(allowedValues);
    super.setAllowedValues(allowedValues);
    return allowedValues;
}

@Override
public void initialize() {
    System.out.println("Initialized called in ClientNameConstraint....................................");
    super.initialize();
    checkPropertyNotNull(ALLOWED_VALUES_PARAM, allowedValues);
}

}
1
  • I would revise your title to reflect that you are trying to make a custom field based off of a dynamic list of folders
    – matthew p.
    Dec 23, 2015 at 17:14

1 Answer 1

1

I would avoid using a constraint in this case. Others may disagree, but a dynamic constraint could be more trouble than it is worth. This is because you can get integrity exceptions which could be messy to deal with if your client list ever gets out of sync. Imagine if you create some documents with one version of the list, but then delete a folder. Now any operation on those documents will throw an integrity exception.

I personally would create a webscript (it could be in Javascript if you like) which reads out the folders and returns them as JSON. Then, I would create a custom share component and configure my form to use this component. The component would build the list of vales from your webscript but would not depend on a constraint.

It's "more" development than your original idea, but it's more flexible and you won't have any issues with upgrades, etc, if your client folders get out of sync with the content.

3
  • @Mathew - Thanks for responding but I didn't get your suggestion, as I am going to query the database for folders name so even if the user deletes a folder than it is not going to be shown in the dropdown. Please let me know if my understanding is wrong. Also I would really appreciate if you can show me a dummy example of what you have said as I am new to Alfresco, it will help me in giving a headstart.. Dec 24, 2015 at 9:37
  • 1
    The issue is not with the deleted folder disappearing from the drop down. If you use a constraint, Alfresco enforces the integrity of the content that is using the constraint. If the available values change because a folder is deleted, any content that referenced that folder will no longer be valid.....There are many tutorials available about creating a dynamic form control, for example: forums.alfresco.com/forum/developer-discussions/…
    – matthew p.
    Dec 25, 2015 at 10:34
  • Integrated the value assistance project with my project for creating a dropdown tied to a datalist. Here is the link to the value assistance project. May 11, 2016 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.