[SalesForce] Make an inputfield readonly depending on a controller boolean variable

I have an inputfield in an apex page

In my apex class there is a boolean variable depending on which this inputfield should be readonly or readwrite. I have tried using rendered. However that is not serving my purpose as I want the field to be displayed only in readonly format for certain conditions. I am fairly new to salesforce and any help would be really appreciated

Best Answer

You can use apex:outputPanel to render the input field.

<apex:outputPanel rendered="{!show_read_write}">
     <apex:inputField value="{!value}" />
</apex:outputPanel>
<apex:outputPanel rendered="{!NOT(show_read_write)}">
     <apex:inputField value="{!value}" html-disabled="true"/>
</apex:outputPanel>
Related Topic