# Add Validation Logic

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](../../ux-ui-components/smart-forms/buttons-and-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.

<div align="left"><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FzB2xGAKTwN9hXallLhRs%2F0?alt=media" alt=""></div>

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

<div align="left"><img src="https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FkotOnVaj43q7df43QrmL%2F1?alt=media" alt=""></div>

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.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FwvAqwO1AYbqC4U3Ba2gO%2F2?alt=media)

**Java Validation**

ONEWEB Smart Forms have Entity Actions to attach a custom Java class to an entity. Please refer to [Entity Actions](bookmark://_topic_63313ButtonsActions) 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.

![](https://2015371994-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMpDjHWFRUtZ5nJcSfVXd%2Fuploads%2FpY0sDH2DSP9wyg2Y0Tk0%2F3?alt=media)

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](../../../../sample-apps/order-management-app-web/app-designer-customize/validate-order-details-when-back-office-submits) 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.
