Expand my Community achievements bar.

Form-Global Constraints

Avatar

Level 1

I have tried to create Form-Global Constraints in CQ5.For this I used http://forums.adobe.com/message/4698545#4698545

I added attribute as validationRT = apps/<myproj>/components/form/default/field/servervalidation.jsp

I have done some log writing on it which is properly getting printed.

I have added some code to check if field X  is not hidden then apply constraint check and if it is hidded then do not do anything.

I have also added log in /libs/foundation/components/form/defaults/field/servervalidation.jsp.

The form start and end is taken from lib only and not copied in my project.

The other components have been added in my project and then dragged to the form in the parasys.

What I observe are the followings:

    1. logs in /libs/foundation/components/form/defaults/field/servervalidation.jsp. get printed first and then logs in /apps/myproj/components/form/defaults/field/servervalidation.jsp get printed thus all the validations already happen at the foundation level so no use handling any validation in my servervalidation.jsp.

2. When I delete the contents of /libs/foundation/components/form/defaults/field/servervalidation.jsp. then it starts printing all the errors of my /apps/<myproj>/components/form/defaults/field/servervalidation.jsp .

3. My form start and end tag is from cq5 ie. sling:resourceType=foundation/components/form/start and sling:resourceType=foundation/components/form/end.

4. My other controls come from /apps/<myproj>/components/form/

5. My action is of type store and action type is mail.

At the end what I want:

1.The form-global validation from my apps/<myproj>/components/form/default/field/servervalidation.jsp  should be called and not the one in the /libs/foundation/components/form/defaults/field/servervalidation.jsp so that only my validations should be checked and not the default one from foundation.

2. What is the flow when we submit a form. what flows does it take to reach the page back after validation?

3. After checking the validation what happens to the code...where it moves on...?

 

Here is a part of code for adding validation...

            final Node par = currentNode != null ? currentNode.getParent() : null;
            final NodeIterator nodes = par != null ? par.getNodes() : null;
            // get all form names for the current paragraph system
            while (nodes != null && nodes.hasNext()) {
                final Node node = nodes.nextNode();
                paraResource = resolver != null ? resolver.getResource(node.getPath()) : null;
                descs = FieldHelper.getFieldDescriptions(slingRequest, paraResource);

                feature         = FormsHelper.getValue(slingRequest,paraResource,"feature");
                
                for(final FieldDescription desc : descs) {
                         valueReceived  =    FormsHelper.getValue(slingRequest,paraResource,desc.getName());
                         descName       =     desc != null ? desc.getName() : null;
                         if( feature.equals("feature1")  && descName.equals("feature1Exps") )
                         {
                             //apply validation
                             if ( FieldHelper.checkRequired(slingRequest, desc) )
                             {
                                     FieldHelper.checkConstraint(slingRequest, slingResponse, desc);
                             }  

                            
                         }
                         else
                         {
                            //no need to validate
                         }
                }
            }

Thanks in advance.

0 Replies