+ Start a Discussion
David VPDavid VP 

Set or update standard object fields from controller extension ... why doesn't it work ?

A simple example based on what's in the VF docs :


<apex:page standardController="Account" extensions="myControllerExtension">
    <apex:form >
        <apex:PageBlock >
            <apex:pageblockSection >
                <apex:inputField value="{!account.name}"/>  
                <apex:inputfield value="{!account.website}"/>
            </apex:pageblockSection>
            <apex:commandButton value="Custom Action" action="{!customsave}"></apex:commandButton>
        </apex:PageBlock>
    </apex:form>
</apex:page>

... and the controller extensions :


public class myControllerExtension {

    private final Account acct;
   
    // The extension constructor initializes the private member
    // variable acct by using the getRecord method from the standard
    // controller.
    public myControllerExtension(ApexPages.StandardController stdController) {
        this.acct = (Account)stdController.getRecord();
    }
   
    public PageReference customsave() {
        acct.website = 'somenewvalue';
        return null;
    }
}

I would image that the account object that's being held in the viewstate would get updated and that after the page refresh it would simply display the new in-memory value ... but it doesn't. In fact this code does nothing at all.

Am I thinking too much in 'managed beans' terms here ? What am I missing ?


Thanks,

David





ESES
I think that value is getting updated but inputField is having trouble rerendering it inside a pageblocksection. If you change inputfield that shows website to inputtext your page works. Also moving inputField out of pagepagesection fixes rerendering (but I guess that messes up the styling :)).
Although like Ron suggested, you are always welcome to use rerender attribute to back you UI look ajaxy.
dchasmandchasman
This is not a behavioral difference between full page and partial page updates at all - neither works correctly. The following workaround will keep you moving:

Code:
<apex:page standardController="Account" extensions="myControllerExtension">
    <apex:form >
        <apex:PageBlock id="pb">
            <apex:pageblockSection>
                <apex:inputField value="{!account.name}"/>  
                <apex:pageBlockSectionItem>
                    {!$ObjectType.account.fields.website.label}
                    <apex:inputField value="{!account.website}"/>
                </apex:pageBlockSectionItem>
            </apex:pageblockSection>
            <apex:commandButton value="Custom Action" action="{!customsave}"/>
        </apex:PageBlock>
    </apex:form>
</apex:page>

wrapping the apex:inputField into a apex:pageBlockSectionItem seems to correct the update issue. We're looking into getting this fixed.



Message Edited by dchasman on 06-25-2008 06:44 PM
David VPDavid VP
Ok,

thanks for the replies and confirming the issue (now I can sleep again :p ).

The workaround will do for now.


keep up the good work !!