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
hunkherehunkhere 

How do I make VF Page as read-only after clickin of Submit/save button

Hello Everyone,

 

  I have a requirement, when users fills the data in the VF Page and clicks save/submit button, after clciking the VF Page should be Read-only and should not be editable.

 

Please help me out

 

 

Thanks

 

bob_buzzardbob_buzzard

You'll need to flip all of your input fields to output fields.  You can do this by setting a 'readonly' boolean or similar in your controller, and then having page markup like the following:

 

<apex:inputField value="{!myobj.My_Field__c}" rendered="{!NOT(readonly)}"/>
<apex:outputField value="{!myobj.My_Field__c}" rendered="{!readonly}"/>

 

hunkherehunkhere

when I save the record it shows read-only, but when I refresh the same record on VF page by pressing F5 record still the fields are editable .

 

I am setting up a getter setter varibale for a boolean like

public boolean Filed_Name{get;set;}

and in save method I am flipping the boolean variable to True.

 

 

bob_buzzardbob_buzzard

By hitting F-5 you have refreshed the page and I'd expect this to create a new instance of the controller, which would mean the booleans default back to false.  Does this page allow creation of records or editing of existing records?  If the latter, you'll need to mark the record as no longer allowed to be edited.

hunkherehunkhere

Yes this page is used to create the records, once click on save button the entire page should get read-only, should not be editable after save even if you press F-5

bob_buzzardbob_buzzard

When you press F-5, do the values remain in the fields and become editable or are they blanked out?

hunkherehunkhere

after saving if I pressed F-5 the fileds should go read-only should not be editable again.

bob_buzzardbob_buzzard

I got that - I'm asking what is actually happening.

hunkherehunkhere

Currently after pressing F-5 Records are still editable

 

if I save recod fields are getting read-only

 

and if  I press F-5 again page is editable...actually it should show read only

hunkherehunkhere

When you press F-5, do the values remain in the fields and become editable or are they blanked out?

 

when I press F-5 the values are getting displaying and editable, actullay it should not be editable. The field values should remain as read-only after I press F-5

bob_buzzardbob_buzzard

Do you flip the booleans to display each time the form is submitted - i.e. you reverse the existing value?  

hunkherehunkhere

HI,

 

here is my code follows 

 

Controller:

 

public class myClass {

 

 public boolean readonlyflag  {get;set;}

 

 public myClass(ApexPages.StandardSetController stdController) {

readonlyflag   = flase;

}

 

public PageReference saveInfo() {
System.debug('saving Record');
try {
upsert(record);
readonlyflag = true;
}
catch(System.DMLException e) {
ApexPages.addMessages(e);
for (Integer i = 0; i < e.getNumDml(); i++) {
System.debug(e.getDmlMessage(i)); 
}
return null;
}

 

}

 

VF PAge:

<apex:page controller="mycontroller" showHeader="false" sidebar="false" >

<apex:pageBlockSectionItem >
<apex:outputLabel value="Date of Birth" for="FIELD" title="{!$ObjectType.OBJ__c.Fields.DOB__c.inlineHelpText}" rendered="{!NOT(readonlyflag)}"/>
<apex:InputField id="FIELD" required="false" value="{!OBJ.DOB__C}" rendered="{!NOT(readonlyflag)}"/>
</apex:pageBlockSectionItem>

 

<!-- Read-Only -->
<apex:pageBlockSectionItem >
<apex:outputLabel value="Date of Birth" for="FIELDRO" title="{!$ObjectType.OBJ__c.Fields.DOB__C.inlineHelpText}" rendered="{!readonlyflag}"/>
<apex:OutputField id="FIELDRO" value="{!OBJ.DOB__C}" rendered="{!readonlyflag}"/>
</apex:pageBlockSectionItem>

BUTTONS:

<apex:pageBlockButtons >
<apex:commandButton action="{!saveInfo}" value="Save"/>
</apex:pageBlockButtons>

</apex:page>

bob_buzzardbob_buzzard

This implies that there is a new instance of the controller being created - the readonly flag is only set to false in the constructor.  I suspect the browser is being helpful by retaining the previously entered value.  The only way I can think of to handle this is to redirect the user to the readonly page.  That way if they refresh it will just hit the readonly page again.

Shobhit TShobhit T
Hi @bob ,

I have similar request , could you please help. :(

Regards,
Shobhit
Vineela Rekha somarajupalliVineela Rekha somarajupalli
Hi,
How to make visualforce page read only and need to get the count entered by each user on that particulat vf page.

Thanks,
Vineela.