function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sami ShakithSami Shakith 

Simple example for disable attribute in command button

Hi i just need to disable a buitton in a page and also know the difference between rendered and rerender attribute. Please give a clear answer with simple example. becouse i am new to salesforce.
Best Answer chosen by Sami Shakith
sandeep sankhlasandeep sankhla
Yes, we can set the value also from css and from any bollena varioables also...
<apex:commandbutton disabled= "{!isDisabled}"  rendered="{!vbutton}" action="{!View}" value="View"   class="faded"/>

like disabled= "{!isDisabled}"   also you can use one bollena varaible which you can set from you page or apex and use..
 

All Answers

sandeep sankhlasandeep sankhla
Hi Sami,

Please use below code to disable the command button

<apex:commandButton action="{!save}" value="Save" id="theButton" disabled = "true"/>

Rendered - rendered means when you conditionally want to show apex component then we use this attribute..like you have one outputpanel where you are showing some data from list...no wif that list is empty then you want to show message else you want to show data...or based on any boolean valye you want to show some panel then we should use rendered..

<apex:outputpanel  id="dummy" rendered="isCheckboxChecked">
</apex:outputpanel>

In above example outputpanel will display the conetent if isCheckboxChecked is true only...

rerender - it is same as refersh..if based on some event you want to refersh somepanel to show the latest data then we use this...

Example - If you are showing contacts in a panel related to account..now onclick of on ebutton you went to apex class and added one more contact to that account and in list ..now if you want to referesh that sepecific block so that block will show you the all conatcts including the newley added also..then we should use rerender...

<apex:commandButton rerender ="dummy" action="{!save}" value="Save" id="theButton" disabled = "true"/>

<apex:outputpanel  id="dummy" >
</apex:outputpanel>

now once you back from command button then it will refersh the paneel who is having id as dummy...

Please check with these and let me know if it helps you..

Thanks ,
Sandeep
Sami ShakithSami Shakith
Hi sandeep,
thanks for your reply. But i want to know about class for that disable action.

for eg. 
<apex:commandbutton rendered="{!vbutton}" action="{!View}" value="View"/>

If the action is like that means what will be the class?
sandeep sankhlasandeep sankhla
Hi,

Can you elaborate more what exactly you need..

from command button action method you are calling one class method named as View....you check you rpage and their in controller it will be there the class name..

<apex:page controler="className">

Let me knwo if this is what you need or you are asking something else..

Thanks,
Sandeep
Sami ShakithSami Shakith
Actually you are rite. But I just need a example. Am asking for a simple example like that. Please assume a button in a page that button will be controlled by a class. 
sandeep sankhlasandeep sankhla
Hi,

Then you can simply declare a class in style section adn then you can apply that class to that button...

<style>
.faded
{
      max-hight:20px;
       colore:red;
like that you can define attraibute
}
</style>

<apex:commandbutton rendered="{!vbutton}" action="{!View}" value="View"   class="faded"/>

simply declare and use that class to your components..

thanks
Sandeep
Sami ShakithSami Shakith
Sorry i in that example missed disable attribute. If i give that disable attribute means it takes boolean value rite?
sandeep sankhlasandeep sankhla
Hi,

if you want to disable comand button then we directly have attribute called as disabled if thats true then it will disable else not..if you have other button where from a class you want to disable them then you can set the css in styles class which we have defined above to apply that css to all buttons where that class we have applied...

By css..you can set whatever styling you want...for many component we directly have attribut called disabled so there directly you can use that..

 
sandeep sankhlasandeep sankhla
Yes, we can set the value also from css and from any bollena varioables also...
<apex:commandbutton disabled= "{!isDisabled}"  rendered="{!vbutton}" action="{!View}" value="View"   class="faded"/>

like disabled= "{!isDisabled}"   also you can use one bollena varaible which you can set from you page or apex and use..
 
This was selected as the best answer
Sami ShakithSami Shakith
Thanks a lot.