2

I want to toggle edit mode to on/off for <apex:detail> component for account by dynamically setting "inlineEdit" to TRUE/FALSE attribute on click of commandbutton.
Following is my code. It keeps the detail section in editable mode only and on click of commandbutton twice, gives error:

"An internal server error has occurred An error has occurred while processing your request. The salesforce.com support team has been notified of the problem......"

VF Page:

<apex:page standardController="Account" showHeader="true" tabStyle="account" extensions="MyExtensionClass">
    <apex:pageBlock>
        <style>
            .activeTab {
                background-color: #236FBD;
                color: white;
                background-image: none
            }

            .inactiveTab {
                background-color: lightgrey;
                color: black;
                background-image: none
            }
        </style>
        <apex:tabPanel switchType="client" selectedTab="tabdetails" id="AccountTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab">
            <apex:tab label="Details" name="AccDetails" id="tabdetails">
                <apex:detail relatedList="false" title="true" inlineEdit="{!setEdit}" id="detailPageID" />
            </apex:tab>
        </apex:tabPanel>
        <apex:pageBlockSection title="Other Function">
            <apex:form>
                <apex:commandButton action="{!editToggle}" value="Toggle Account  Edit" reRender="detailPageID" />
            </apex:form>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Extension:

public class MyExtensionClass {
    private final Account acc;
    public boolean setEdit {get;set;}
    public MyExtensionClass(ApexPages.StandardController stdController) {
        system.debug('Inside Controller');
        this.acc = (Account) stdController.getRecord();
        setEdit = TRUE;
    }
    public void editToggle() {
        system.debug('setEdit: ' + setEdit);
        if (setEdit == TRUE) {
            setEdit = FALSE;
        }
        ELSE
        setEdit = TRUE;
    }
}
0

1 Answer 1

3

It's look like inlineEdit couldn't be binded with dynamic boolean. Try to create two detail and render them accordingly:

<apex:tab label="Details" name="AccDetails" id="tabdetails">
    <apex:detail relatedList="false" title="true" inlineEdit="true" rendered="{!setEdit}"/>
    <apex:detail relatedList="false" title="true" inlineEdit="false" rendered="{!Not(setEdit)}"/>
</apex:tab>

And also lets change button to rerender whole tabpanel:

<apex:commandButton action="{!editToggle}" value="Toggle Account Edit" reRender="AccountTabPanel"/>

Updated: please find whole page below:

<apex:page standardController="Account" showHeader="true"
           tabStyle="account" extensions="toogleEdit">
    <apex:pageBlock >
        <style>
            .activeTab {background-color: #236FBD; color:white;
            background-image:none}
            .inactiveTab { background-color: lightgrey; color:black;
            background-image:none}
        </style>
        <apex:tabPanel switchType="client" selectedTab="tabdetails"
                       id="AccountTabPanel" tabClass="activeTab"
                       inactiveTabClass="inactiveTab" >
            <apex:tab label="Details" name="AccDetails" id="tabdetails">        
                <apex:detail relatedList="false" title="true" inlineEdit="true" rendered="{!setEdit}"/>
                <apex:detail relatedList="false" title="true" inlineEdit="false" rendered="{!Not(setEdit)}"/>
            </apex:tab>
        </apex:tabPanel>
        <apex:pageBlockSection title="Other Function">
            <apex:form >
                <apex:commandButton action="{!editToggle}" value="Toggle Account Edit" reRender="AccountTabPanel"/>
            </apex:form>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

Result:

enter image description here

4
  • Thanks for answering!! How is this decided which components can be binded and which not? Is any documentation provided for this?
    – Sarang
    Commented Jul 10, 2016 at 7:56
  • 1
    Welcome to the salesforce world Commented Jul 10, 2016 at 8:14
  • This ain't working....On click of toggle button the details go aay and empty tab is shown
    – Sarang
    Commented Jul 17, 2016 at 14:38
  • Works fine in firefox and chrome. Commented Jul 17, 2016 at 15:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .