Reputation: 243
I'm trying to create a form filter, that would do some post-processing of a form.
What I'm trying to achieve: Everytime a node has been created OR modified the filter should be applied after the node is persisted.
It runs just fine when i edit/modify an existing, but it does not run after a new node is created.
Here is my code:
public class CaseFormFilter extends AbstractFilter<Object, NodeRef>
{
protected ServiceRegistry registry;
protected NodeService nodeService;
protected SearchService searchService;
protected SiteService siteService;
protected NamespaceService namespaceService;
public void setServiceRegistry (ServiceRegistry registry)
{
this.registry = registry;
this.nodeService = this.registry.getNodeService();
this.searchService = this.registry.getSearchService();
this.siteService = this.registry.getSiteService();
this.namespaceService = this.registry.getNamespaceService();
}
@Override public void afterPersist(Object item, FormData data, NodeRef persistedObject)
{
System.out.println("Persisting!");
}
@Override public void afterGenerate(Object item, List fields, List forcedFields, Form form, Map context)
{
System.out.println("Calling afterGenerate!!");
}
@Override public void beforeGenerate(Object item, List fields,
List forcedFields, Form form, Map context)
{
System.out.println("Calling beforeGenerate!!");
}
@Override public void beforePersist(Object item, FormData data)
{
System.out.println("Calling beforePersist!!");
}
}
I can see that beforeGenerate
and afterGenerate
is always called, even when viewing, which makes sense.
However, afterPersist
is only run when I edit a node, but not when creating a new node.
Am I doing something wrong or missing something? The wiki/documentation is rather useless on this point, reading http://wiki.alfresco.com/wiki/Forms_Developer_Guide#Form_Filter just tells me to look in the DOD5015 module, which does provide an example, but does not really provide any answers.
I'm using Alfresco 4.0.b Community edition.
EDIT: A bit more clarification
Upvotes: 2
Views: 953
Reputation: 1281
You have to register your form filter twice. I'm guessing you currently only register it with the nodeFilterRegistry
. For a form based on the content model (creating a node) you need to register your filter with the typeFilterRegistry
.
Here is an example for a form filter configuration with both registries:
<bean id="yourFormFilterNode" class="com.domain.YourFormFilter" parent="baseFormFilter">
<property name="filterRegistry" ref="nodeFilterRegistry" />
<property name="nodeService" ref="nodeService" />
</bean>
<bean id="yourFormFilterType" class="com.domain.YourFormFilter" parent="baseFormFilter">
<property name="filterRegistry" ref="typeFilterRegistry" />
<property name="nodeService" ref="nodeService" />
</bean>
Upvotes: 4
Reputation: 6643
It's rather obvious that afterPersist is only called when submitted, because on viewing you're not 'persisting' any data.
So in most case you'll only need before/afterGenerate.
Upvotes: 0