1

I am new to VF so I hope someone here can help me with a problem I have.

I have created a VF page where a checkbox determines if another field should be shown or not. I wanted to use inline editing as well, but then I need to save for the field to show. Is is possible to make the rerender work when editing inline?

This is my code:

<apex:pageBlockSection title="Billing Information" >
<!-- The checkbox which decides who should be billed -->
    <apex:outputField value="{!servicecontract.Invoices_should_be_issued_to_distributor__c}" id="theCheckbox">
        <apex:actionSupport event="onchange" rerender="billingAddress"/>
    </apex:outputfield>
</apex:pageBlockSection>

<apex:pageBlockSection id="billingAddress" columns="2" >
    <apex:outputField id="distributorAccount" label="Distributor account" value="{!servicecontract.Distributor_Account__c}" rendered="{!(servicecontract.Invoices_should_be_issued_to_distributor__c == true)}" />
</apex:pageBlockSection>

<apex:inlineEditSupport event="ondblClick" hideOnEdit="editButton" />

2 Answers 2

2

Yes you can do that. It works fine like on any other page without inline edit support. Here a simple example how to implement this:

Controller:

public with sharing class TestInlineEdit{
    public Account acc { get; set; }

    // Defining an extra boolean variable for rerendering
    public Boolean myBoolean { get; set; }

    public TestInlineEdit(){
        myBoolean = false;
        acc = [Select id, Name, Street__c 
               From Account 
               Where Street__c != null Limit 1];
    }
}

Page:

<apex:page controller="TestInlineEdit">
<apex:form >
    <apex:pageBlock id="myBlock">
        <apex:pageBlockButtons location="top">
            <apex:commandButton id="cancelButton" value="Cancel" style="display:none;"/>

            <!-- Checkbox to show or hide another field -->
            <apex:outputLabel value="Show another field:" for="mycheckbox"/>
            <apex:inputCheckbox value="{!myBoolean}">
                <apex:actionSupport reRender="mySection" event="onchange" id="mycheckbox"/>
            </apex:inputCheckbox>

        </apex:pageBlockButtons>

        <apex:pageBlockSection id="mySection">
            <apex:outputField value="{!acc.Name}"/>
            <apex:outputField value="{!acc.Street__c}" rendered="{!myBoolean}"/>
        </apex:pageBlockSection>

        <apex:inlineEditSupport showOnEdit="cancelButton"
                                resetFunction="reset"
                                event="ondblclick" />
    </apex:pageBlock>
</apex:form>
</apex:page>

A normal state without any editing:

enter image description here

Then editing the first field just to show that a new value will not disappear after rerender:

enter image description here

And now cklicking on the checkbox and the second field appears:

enter image description here

1

You should replace your outputField with either an inputField or inputCheckbox component. In your case where you used outputField (instead of an input component), the value of Invoices_should_be_issued_to_distributor__c field was only fetched through binding, but was not updated in your object, as the outputField presents only a 'one-way' binding between VF page and the underlying controller. With just slightly altered your example, everything should work as expected:

<apex:pageBlockSection title="Billing Information" >
    <!-- The checkbox which decides who should be billed -->
    <apex:inputCheckbox value="{!servicecontract.Invoices_should_be_issued_to_distributor__c}" id="theCheckbox">
        <apex:actionSupport event="onchange" rerender="billingAddress"/>
    </apex:inputCheckbox>
</apex:pageBlockSection>

<apex:pageBlockSection id="billingAddress" columns="2" >
    <apex:outputField id="distributorAccount" label="Distributor account" value="{!servicecontract.Distributor_Account__c}" rendered="{!(servicecontract.Invoices_should_be_issued_to_distributor__c == true)}" />
</apex:pageBlockSection>

<apex:inlineEditSupport event="ondblClick" hideOnEdit="editButton" />

You must log in to answer this question.

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