Using the immediate attribute on CommandLinks and CommandButtons

I came across a great little feature of the VisualForce CommandLink and CommandButton component the other day, when I was working with a client who needed the ability to cancel out of a custom Visual Force page. The use case stated that a user could cancel partway through entering their details, and return them to the Opportunity screen, from where they came.

Simple enough—but they wanted to return without having to fix validation errors before doing so.

VisualForce does a great job of automatically handling a lot of the validation for you so I was happy to come across an attribute of the CommandLink and CommandButton called immediate. By setting immediate to true, validation rules are skipped and the action associated with the button is executed immediately; thus the name!

Here is my nifty, little link, which by using the immediate attribute, solved my clients use case in a snap:

<apex:CommandLink action="{!cancelApplication}" value="Cancel" styleClass="btn" id="btnCancel" immediate="true">

December 4, 2008

Leave your comments...

Using the immediate attribute on CommandLinks and CommandButtons