There are two ways you can add validation logic to ONEWEB Smart Forms.

JavaScript Validation

ONEWEB Smart Forms have Entity Actions to attach a JavaScript file to an entity. Please refer to Entity Actions section for more details on how to attach JavaScript to an entity.


JavaScript validation is used mainly for client-side validations such as check field formats or mandatory fields. First add a JavaScript file to the module action.


Now open the workspace in Eclipse and create the JavaScript file specified in the module action. Add the method to validate.


Build and publish to server. Once deployed to server don't forget to add this validation check to the field on AppDesigner. Click on the pencil edit icon for the field to open the configuration panel. Add the validation call in the source Tag property.


Java Validation

ONEWEB Smart Forms have Entity Actions to attach a custom Java class to an entity. Please refer to Entity Actions section for more details on how to attach Java class to an entity. Java validations are used for server-side validations before saving an Entity. First step is to add an Entity Action and specify the Java class name in the Class Action property.



Once a java class is attached to an entity through Entity Action, open the ONEWEB workspace in eclipse; create the java class as extend from "ProcessHelper" and implements "ProcessAction" interface. Eclipse will create a stub of the class. Now override method "validateResult()" to add custom validation logic before saving entity. Please refer to the validation section in Sample Apps for more detailed examples.


package com.manual.doc.order.java;


import java.util.HashMap;

import java.util.Vector;


import org.apache.log4j.Logger;


import com.manual.service.ManualDAOFactory;

import com.master.form.EntityFormHandler;

import com.master.util.EAFManualUtil;

import com.master.util.ProcessAction;

import com.master.util.ProcessHelper;


public class OrderRequestBackOfficeUpdateMode extends ProcessHelper implements ProcessAction {

       private static Logger logger = Logger.getLogger(OrderRequestBackOfficeUpdateMode.class);


       @Override

       public boolean validateResult() {                

               String nextEntity = request.getParameter("goEntity");

               logger.debug("@@@@@ nextEntity :" + nextEntity);

               

               if(nextEntity == null || "".equals(nextEntity)) {

                       String entityID = (String)getRequest().getSession().getAttribute("entityID");

                       EntityFormHandler entityForm = (EntityFormHandler)getRequest().getSession().getAttribute(entityID +"_session");

                       Vector errorVect = entityForm.getFormErrors();

                       String moduleID = entityForm.getMainModuleID();

                       

                       HashMap mainRequestData = EAFManualUtil.getDataHashMapFromSession(moduleID, request);

                       String requestID = (String)mainRequestData.get("REQUEST_ID");

                       

                       try{

                               int inCompleteAmt = ManualDAOFactory.getManualDocOrderDAO().countInCompleteOrderUnit(requestID);

                               logger.debug("@@@@@ completeAmt :" + completeAmt);

                               if(completeAmt > 0){

                                       errorVect.add("Please verify un-assign order unit.");

                                       return false;

                               }

                       }catch(Exception e){

                               errorVect.add(e.getMessage());

                               return false;

                       }

               }

               return super.validateResult();

       }

}


Once completed build and publish to server. Now ONEWEB will execute this validation check every time before saving the entity.