Even when defining an Alfresco behavior, there are differences in how a behavior is defined, depending on whether properties or associations are the source of the behavior action.
There are a number of tutorials or examples in blog articles that describe how to define a behavior in Alfresco, but most focus on behaviors that involve properties and not associations. In this post, let's look at what is involved in creating a behavior triggered by the addition or deletion of an association.
First, we create a custom content model, called AspectTest.xml, as follows:
Put it into the alfresco/extension/models directory. This defines an association and a text field.
Then create the file to tell Alfresco to use the custom content model. Create the file testaspect-context.xml and place it in the alfresco/extension directory.
The first of these invokes the behavior when associations are deleted, and the second is invoked when associations are added.
One of the peculiarities of Alfresco associations is that they are not searchable by queries. As a workaround, this behavior will enable the search of user names selected by an association picker and stored the picked results in a text field. The text field can be searched, even though the association cannot.
That's almost all. But there is also some code involved in setting up the picker on an Alfresco search form. For example, we can add the following extension configuration into Share to enable the assignment of our new association and also the display of it on a form.
The picker control for the association in Share will look like this:
And, using the above example picker results, user mjackson can be searched for as follows by searching on the text property which is synced with the values in the association (aspt:projManager:mjackson):