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
Ramesh SomalagariRamesh Somalagari 

VF page fields after click the save button read only(view)

VF page fields after click the save button read only(view)
Hi

I have one VF page that contains custom fields:
**VF Page : DEMO**
<apex:page standardController="Order__c" extensions="MyOrderPadController" >      
     <apex:detail />
        <apex:form >   
        <apex:pageBlock >     
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!edit}" value="Edit"/>
                <apex:commandButton action="{!reset}" value="Cancel" />
            </apex:pageBlockButtons>                      
            <apex:pageBlockSection columns="2" title="Order Pad">
            <apex:inputField value="{!Order__c.Order_Description__c}"  />
                    <apex:inputField value="{!Order__c.Creat_Date__c}"  />
                    <apex:inputField value="{!Order__c.Closed_Date__c}"  />
                     <apex:inputField value="{!Order__c.Conformation__c}"  />                                         
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
   
</apex:page>

**Controller :MyOrderPadController**

public class MyOrderPadController {
    public Order__c order{ get; private set;
}            
  
        public MyOrderPadController ()
       {
         
       }
    public MyOrderPadController(ApexPages.StandardController sc) {
       
        order = (Order__c)sc.getRecord();
        order.Account__c = ApexPages.currentPage().getParameters().get('aid'); 
    }
public PageReference edit()
     {
           return null;       
     }
     public PageReference reset()
     {
          PageReference newpage = new PageReference(System.currentPageReference().getURL());
        
          newpage.setRedirect(true);
          return newpage;
    }
     public PageReference save()
     {
          TRY
          {             
               order.Name = 'Demo ';                                     
                IF(order.Conformation__c == TRUE){                         
                    INSERT order;
                    PageReference newpage = new                PageReference(System.currentPageReference().getURL());
                    newpage.setRedirect(true);
                    return newpage;    
                    }
                  
                    
                    }  
         
          catch(System.DMLException e)
          {
            ApexPages.addMessages(e);
            SYSTEM.DEBUG('ERROR ORDER PAD CONTROLLER :'+e);
            return null;
          }
       
        return null;       
     }  
}

My question is after click the save button all fields in the VF page not editable (read only),future edit possible,User where ever click the conformation checked then at the time only record is insert in the "Order__c",user unchecked conformation  then click the save button save the VF page read only.Please some one help me.

Thanks & Best Regards,
Ramesh
Best Answer chosen by Ramesh Somalagari
KodiKodi
Hi,
If you want to read only fields for after click the save button means, you have to rendered two pageblock sections. One block input fields and another one output fields.
Example:
<apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!edit}" value="Edit"/>
                <apex:commandButton action="{!reset}" value="Cancel" />
            </apex:pageBlockButtons>
<apex:pageblocksection rendered="{!rend}">
<apex:inputField value="{!Order__c.Order_Description__c}"  />
                    <apex:inputField value="{!Order__c.Creat_Date__c}"  />
                    <apex:inputField value="{!Order__c.Closed_Date__c}"  />
                     <apex:inputField value="{!Order__c.Conformation__c}"  />                                        
            </apex:pageBlockSection>

<apex:pageblocksection rendered="{!rend1}">
<apex:outputField value="{!Order__c.Order_Description__c}"  />
                    <apex:outputField value="{!Order__c.Creat_Date__c}"  />
                    <apex:outputField value="{!Order__c.Closed_Date__c}"  />
                     <apex:outputField value="{!Order__c.Conformation__c}"  />                                        
            </apex:pageBlockSection>

controller:
public class MyOrderPadController
{
public boolean rend{get;set;}
public boolean rend1{get;set;}
MyOrderPadController(Apex........................)
{
rend=true;
rend1=false;
}
public PageReference save()
{
insert order;
rend=false;
rend1=true;
return null;
}

All Answers

KodiKodi
Hi,
If you want to read only fields for after click the save button means, you have to rendered two pageblock sections. One block input fields and another one output fields.
Example:
<apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
                <apex:commandButton action="{!edit}" value="Edit"/>
                <apex:commandButton action="{!reset}" value="Cancel" />
            </apex:pageBlockButtons>
<apex:pageblocksection rendered="{!rend}">
<apex:inputField value="{!Order__c.Order_Description__c}"  />
                    <apex:inputField value="{!Order__c.Creat_Date__c}"  />
                    <apex:inputField value="{!Order__c.Closed_Date__c}"  />
                     <apex:inputField value="{!Order__c.Conformation__c}"  />                                        
            </apex:pageBlockSection>

<apex:pageblocksection rendered="{!rend1}">
<apex:outputField value="{!Order__c.Order_Description__c}"  />
                    <apex:outputField value="{!Order__c.Creat_Date__c}"  />
                    <apex:outputField value="{!Order__c.Closed_Date__c}"  />
                     <apex:outputField value="{!Order__c.Conformation__c}"  />                                        
            </apex:pageBlockSection>

controller:
public class MyOrderPadController
{
public boolean rend{get;set;}
public boolean rend1{get;set;}
MyOrderPadController(Apex........................)
{
rend=true;
rend1=false;
}
public PageReference save()
{
insert order;
rend=false;
rend1=true;
return null;
}
This was selected as the best answer
Ramesh SomalagariRamesh Somalagari
Thanks now it is working.