+ Start a Discussion

Validation routine in a controller

I would like to create a generic validation routine in a controller - i.e., when the Save button is clicked on a page, the validation routine executes, errors are trapped, and the cursor/focus is placed in the appropriate field on the page.


I have a general idea of how this should work, but not sure how to have the page communicate with the controller.



Barb R.


Here's a simplified view of how you could implement this:


First, override the object's New or Edit buttons with a Visualforce Page.


In the  Visualforce page, add your controller as an extension


<apex: page standardController="Your_Object__c" extensions="Your_Controller_Ext">


Use a command button on the visualforce page to "communicate" with the controller


<apex:commandButton value="Save" action="{!save}" / >


Define your custom validation/save routine in the controller:


public class Your_Controller_Ext{

    public PageReference save(){

        //Your validation/save routine goes here





Thanks, Captain...I was looking more for how to set the screen focus on a field that had failed vailidation in the controller.