0

It could be the possible duplicate of this question. All I need to know how can I utilize this technique explained in the answer of this question?

1

An <apex:outputField value={!someField} />is a readonly field. You would need to pass a value from your controller to determine whether or not to use input or output.

public with sharing class MyCustomController {

public Boolean ReadOnly {get; set;}

public MyCustomController()
{
   ReadOnly = true;
}

public PageReference SwitchViews()
{
   ReadOnly = !ReadOnly;
   return null;
}

}

Then for your visual force page:

<apex:page controller="MyCustomController">
   <apex:form id="myform">
     <apex:commandLink value="Switch Views" action="{!SwitchViews}" rerender="myform" />
     <apex:outputPanel rendered="{!ReadOnly}">
              Will be displayed when ReadOnly = true
     </apex:outputPanel>
     <apex:outputPanel rendered="{!NOT(ReadOnly)}" >
              Will be displayed when ReadOnly = false
     </apex:outputPanel>
   </apex:form>    
</apex:page>

Without fully seeing where you want to go, I just want to point out that if the user does not have edit permissions on the Object but have Read capabilities that standard Salesforce behavior would be to show in read only. So it may be possible to have the desired effect by configuring permissions on the objects which would be recommended whenever possible.

In the example above, you would use the where ReadOnly = true, and the where ReadOnly = false; where {!someField} is a field on the object that you are trying to display to the user.

  • I want to redirect to my VF page on clicking at the event record. And on that VF page I want to have an Edit button which will let the user to edit the record he is currently on. And initially page will be in the read-only state. – Superman Jan 18 '15 at 7:58
  • I've updated the code above, to allow you to switch views between a 'read-only' and a 'non read-only'. – TC Sutton Jan 18 '15 at 17:30
  • Thanks. I'll try it as soon as possible. Just trying to fix another thing right now :) Thanks for your help. – Superman Jan 18 '15 at 17:35
  • Just to make your page readonly you can use attribute that comes with Apes:page tag. developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… – salesforcewithfunforce Nov 10 '15 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.