cancel
Showing results for 
Search instead for 
Did you mean: 

Registering Form Filters

peterzmlim
Champ in-the-making
Champ in-the-making
Hi,

I would like to develop a Form Filter to process some data from a form before and after the form is generated. I've looked into the Form Wiki and also the DOD5015 source code, but I'm still a lil confused.

After registering the form filter bean, how do I designate/configure the formfilter for a specific formid/itemkind?

Regards,
peterzmlim
3 REPLIES 3

jpfi
Champ in-the-making
Champ in-the-making
Hi,
add your bean like this (Node Filter here):

<bean id="myCustomFormFilter" class="xxx.MyCustomFormFilter" parent="baseFormFilter">
      <property name="nodeService" ref="nodeService" />      
      <property name="filterRegistry" ref="nodeFilterRegistry" />
   </bean>

and implement your filter like this:

    public void afterGenerate(ItemType item, List<String> fields, List<String> forcedFields, Form form,
            Map<String, Object> context) {
        if (item instanceof NodeRef)
        {
            final NodeRef nodeRef = (NodeRef) item;
            if (nodeService.exists(nodeRef) && nodeService.getType(nodeRef).equals(MyModel.TYPE_MYTYPE)){
               final NodeRef parentRef = this.nodeService.getPrimaryParent(nodeRef).getParentRef();
                    ….        
        }
    }

Cheers, Jan

peterzmlim
Champ in-the-making
Champ in-the-making
Dear Jan,

Thanks for the reply.

Just to clarify. So, from your code. I would have to designate the filter to a specific node/form via checking within the Java implementation. which means that this filter (or every other implemented filters) will be checked against every form?

jpfi
Champ in-the-making
Champ in-the-making
yub 😉