Thursday 23 June 2011

Conditional Style and disabled attribute in Apex

I faced a problem that how we can use some attributes like style and disabled on any condition .
Here I want to share the approach that -
1) How to apply style on any condition
2) How to use disabled on any condition
Explanation  is given below with an example (To disable locked Accounts and to change background color for that account )

VF Page code :-
  

    
        
            
                
                    
                    
                           
                       
                
             
           
               
                   
               
       
   


Controller Code:-
  
public with sharing class Styewithcondition {
    public List accList{get;set;}
    //constructor 
    public styewithcondition(){
        accList = [select name,Locked__c from Account where name like 'a%'];
    }
    public void lockAccount(){
        update accList;
    }
    public void UnlockAllAccount(){
       for(Account a:  accList )
       {   if(a.locked__c == true)
           a.locked__c = false;
       }
       update accList;
    }
}

Screen Shot :-
By this code you can lock and unlock Account from a single list.

No comments:

Post a Comment