Skip to main content
added 358 characters in body
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431

I have a VF page in which I am saving and adding the values through two buttons. Buttons are working fine. when i click the add button, a new row is added and when i click on save button,data is saved in Read only mode. But when i refresh the page , the values are saved in edit mode and not in read only mode. So, my questions is how to Save the Data in Read only mode on Page refresh. My Vf Page code :- <apex:page standardcontroller="Assigned_tasks__c" extensions="TestTaskController1"> <apex:form > <apex:pageBlock >


</apex:column> <apex:column headerValue="Comments"> <apex:inputField value="{!acc.Comments__c}"/> </apex:column>
</apex:pageBlockTable> </apex:pageBlockSection>



</apex:pageBlockTable> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Add Report" action="{!addAccount}"/> <apex:commandButton value="Save Report" action="{!saveAccount}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>

Apex Class :-

public class TestTaskController1 {Visualforce Page:

Report_Information__c task = new Report_Information__c(); Public boolean saved {get; set;} Public boolean saved1 {get; set;} public String parentId;

<apex:page standardcontroller="Assigned_tasks__c" extensions="TestTaskController1">
<apex:form >
<apex:pageBlock > 
<div id="hide">
 <apex:pageBlockSection title="Input Page" id="pgsec" rendered="{!saved}">
<apex:pageBlockTable value="{!reportlist}" var="acc"> 
<apex:column headerValue="Report Name"> 
<apex:inputField value="{!acc.Report_Name__c}" /> 

 <br /> </apex:column> 
  <apex:column headerValue="Comments">
 <apex:inputField value="{!acc.Comments__c}"/> 
 </apex:column> 
 <br/>
 </apex:pageBlockTable>
  </apex:pageBlockSection>
  </div>
 <apex:pageBlockSection title="Output Page"  rendered="{!saved1}">
 <apex:pageBlockTable value="{!reportlist}" var="acc"> 
 
 <apex:column headerValue="Report Name"> 
<apex:outputField value="{!acc.Report_Name__c}" />
 </apex:column> <br/>
  <apex:column headerValue="Comments">
<apex:outputField value="{!acc.Comments__c}" /> 
<br /> </apex:column> 

</apex:pageBlockTable>
 </apex:pageBlockSection>
 <apex:pageBlockButtons > 
<apex:commandButton value="Add Report" action="{!addAccount}"/>
 <apex:commandButton value="Save Report" action="{!saveAccount}"/> 
</apex:pageBlockButtons>
 </apex:pageBlock> 
</apex:form>
</apex:page>

public list<Report_Information__c> reportlist{ get; set; }Apex Class:

public class TestTaskController1 {

Report_Information__c task = new Report_Information__c();
Public boolean saved {get; set;}
Public boolean saved1 {get; set;}
public String parentId;

public list<Report_Information__c> reportlist{ get; set; }

    public TestTaskController1(ApexPages.StandardController controller) {
              reportlist=new list<Report_Information__c>();
              parentId= controller.getId();
              reportlist = [SELECT id,Report_Name__c,Comments__c,ATask__c from Report_Information__c where ATask__c=:parentId];              
              reportlist.add(task);
              saved=true;
              saved1 = false;
            
              
    }


Public void addAccount()
{
Report_Information__c acc = new Report_Information__c();
reportlist.add(acc);
saved=true;
saved1=false;
}


public PageReference saveAccount() {
for(Report_Information__c  re :reportlist)
{

re.ATask__c= parentId;
}

if(reportlist.size()>1){
insert reportlist;
saved=false;
saved1= true;


}

return null;

}}

Public void addAccount() { Report_Information__c acc = new Report_Information__c(); reportlist.add(acc); saved=true; saved1=false; }

public PageReference saveAccount() { for(Report_Information__c re :reportlist) {

re.ATask__c= parentId; }

if(reportlist.size()>1){ insert reportlist; saved=false; saved1= true;

}

return null;

}}

My VF page :-Visualforce Screenshot: enter image description here

I have a VF page in which I am saving and adding the values through two buttons. Buttons are working fine. when i click the add button, a new row is added and when i click on save button,data is saved in Read only mode. But when i refresh the page , the values are saved in edit mode and not in read only mode. So, my questions is how to Save the Data in Read only mode on Page refresh. My Vf Page code :- <apex:page standardcontroller="Assigned_tasks__c" extensions="TestTaskController1"> <apex:form > <apex:pageBlock >


</apex:column> <apex:column headerValue="Comments"> <apex:inputField value="{!acc.Comments__c}"/> </apex:column>
</apex:pageBlockTable> </apex:pageBlockSection>



</apex:pageBlockTable> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Add Report" action="{!addAccount}"/> <apex:commandButton value="Save Report" action="{!saveAccount}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>

Apex Class :-

public class TestTaskController1 {

Report_Information__c task = new Report_Information__c(); Public boolean saved {get; set;} Public boolean saved1 {get; set;} public String parentId;

public list<Report_Information__c> reportlist{ get; set; }

public TestTaskController1(ApexPages.StandardController controller) {
          reportlist=new list<Report_Information__c>();
          parentId= controller.getId();
          reportlist = [SELECT id,Report_Name__c,Comments__c,ATask__c from Report_Information__c where ATask__c=:parentId];              
          reportlist.add(task);
          saved=true;
          saved1 = false;
        
          
}

Public void addAccount() { Report_Information__c acc = new Report_Information__c(); reportlist.add(acc); saved=true; saved1=false; }

public PageReference saveAccount() { for(Report_Information__c re :reportlist) {

re.ATask__c= parentId; }

if(reportlist.size()>1){ insert reportlist; saved=false; saved1= true;

}

return null;

}}

My VF page :- enter image description here

I have a VF page in which I am saving and adding the values through two buttons. Buttons are working fine. when i click the add button, a new row is added and when i click on save button,data is saved in Read only mode. But when i refresh the page , the values are saved in edit mode and not in read only mode. So, my questions is how to Save the Data in Read only mode on Page refresh.

Visualforce Page:

<apex:page standardcontroller="Assigned_tasks__c" extensions="TestTaskController1">
<apex:form >
<apex:pageBlock > 
<div id="hide">
 <apex:pageBlockSection title="Input Page" id="pgsec" rendered="{!saved}">
<apex:pageBlockTable value="{!reportlist}" var="acc"> 
<apex:column headerValue="Report Name"> 
<apex:inputField value="{!acc.Report_Name__c}" /> 

 <br /> </apex:column> 
  <apex:column headerValue="Comments">
 <apex:inputField value="{!acc.Comments__c}"/> 
 </apex:column> 
 <br/>
 </apex:pageBlockTable>
  </apex:pageBlockSection>
  </div>
 <apex:pageBlockSection title="Output Page"  rendered="{!saved1}">
 <apex:pageBlockTable value="{!reportlist}" var="acc"> 
 
 <apex:column headerValue="Report Name"> 
<apex:outputField value="{!acc.Report_Name__c}" />
 </apex:column> <br/>
  <apex:column headerValue="Comments">
<apex:outputField value="{!acc.Comments__c}" /> 
<br /> </apex:column> 

</apex:pageBlockTable>
 </apex:pageBlockSection>
 <apex:pageBlockButtons > 
<apex:commandButton value="Add Report" action="{!addAccount}"/>
 <apex:commandButton value="Save Report" action="{!saveAccount}"/> 
</apex:pageBlockButtons>
 </apex:pageBlock> 
</apex:form>
</apex:page>

Apex Class:

public class TestTaskController1 {

Report_Information__c task = new Report_Information__c();
Public boolean saved {get; set;}
Public boolean saved1 {get; set;}
public String parentId;

public list<Report_Information__c> reportlist{ get; set; }

    public TestTaskController1(ApexPages.StandardController controller) {
              reportlist=new list<Report_Information__c>();
              parentId= controller.getId();
              reportlist = [SELECT id,Report_Name__c,Comments__c,ATask__c from Report_Information__c where ATask__c=:parentId];              
              reportlist.add(task);
              saved=true;
              saved1 = false;
            
              
    }


Public void addAccount()
{
Report_Information__c acc = new Report_Information__c();
reportlist.add(acc);
saved=true;
saved1=false;
}


public PageReference saveAccount() {
for(Report_Information__c  re :reportlist)
{

re.ATask__c= parentId;
}

if(reportlist.size()>1){
insert reportlist;
saved=false;
saved1= true;


}

return null;

}}

Visualforce Screenshot: enter image description here

Source Link

Show Saved Records in Read Only Mode on Refresh

I have a VF page in which I am saving and adding the values through two buttons. Buttons are working fine. when i click the add button, a new row is added and when i click on save button,data is saved in Read only mode. But when i refresh the page , the values are saved in edit mode and not in read only mode. So, my questions is how to Save the Data in Read only mode on Page refresh. My Vf Page code :- <apex:page standardcontroller="Assigned_tasks__c" extensions="TestTaskController1"> <apex:form > <apex:pageBlock >


</apex:column> <apex:column headerValue="Comments"> <apex:inputField value="{!acc.Comments__c}"/> </apex:column>
</apex:pageBlockTable> </apex:pageBlockSection>



</apex:pageBlockTable> </apex:pageBlockSection> <apex:pageBlockButtons > <apex:commandButton value="Add Report" action="{!addAccount}"/> <apex:commandButton value="Save Report" action="{!saveAccount}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>

Apex Class :-

public class TestTaskController1 {

Report_Information__c task = new Report_Information__c(); Public boolean saved {get; set;} Public boolean saved1 {get; set;} public String parentId;

public list<Report_Information__c> reportlist{ get; set; }

public TestTaskController1(ApexPages.StandardController controller) {
          reportlist=new list<Report_Information__c>();
          parentId= controller.getId();
          reportlist = [SELECT id,Report_Name__c,Comments__c,ATask__c from Report_Information__c where ATask__c=:parentId];              
          reportlist.add(task);
          saved=true;
          saved1 = false;
        
          
}

Public void addAccount() { Report_Information__c acc = new Report_Information__c(); reportlist.add(acc); saved=true; saved1=false; }

public PageReference saveAccount() { for(Report_Information__c re :reportlist) {

re.ATask__c= parentId; }

if(reportlist.size()>1){ insert reportlist; saved=false; saved1= true;

}

return null;

}}

My VF page :- enter image description here