1

I have this code with inline edit support. When I hit save the changes are not saved - I see that the currentCatalogItem which is sent to be updated does not have the value I changed.

What am I doing wrong?

Page:

<apex:commandButton action="{!saveCatalogItem}" id="saveButton" value="Save" style="display:none"/>    

<apex:pageBlockSection columns="2">
   <apex:outputField value="{!Portfolio_Catalog_Item__c.edit_Short_Name__c}">
         <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" event="ondblclick" hideOnEdit="editButton, approveButton, deleteButton, cloneButton" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
    </apex:outputField>
<apex:pageBlockSection columns="2">

Controller Extension:

public pageReference saveCatalogItem() {
       try {
           update currentCatalogItem;
       }
       catch(Exception e){
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, e.getMessage()));
       }
       return null;
}
6
  • I see you are adding an apex message, but do you have an <apex:messages> tag on your VF page? IF not, you need to add one to see if there is an error being created. Without that tag, an error is being added, but you have no way to know what it is. Commented Oct 15, 2013 at 14:13
  • I think you need to update Portfolio_Catalog_Item__c object? Commented Oct 15, 2013 at 14:14
  • I think you need to replace Portfolio_Catalog_Item__c.edit_Short_Name__c with currentCatalogItem.edit_Short_Name__c in your VF page Commented Oct 15, 2013 at 14:15
  • I have apex:pagemessages. is there any difference?
    – Dedo
    Commented Oct 15, 2013 at 14:23
  • that is what I meant, sorry, so you do have that. ok, just checking Commented Oct 15, 2013 at 14:29

2 Answers 2

1

I have also faced the same issue. You can resolve this by first changing the focus of the Inline Edit to some other element (say a hidden input type). This will send your updated value back to the controller.

Try the below updated code.

Page:

<script>
function callMyFunc(){
   document.getElementById('focusMe').click();
   actionFuncToUpdate();    
 }
</script>
<apex:actionFunction action="{!saveCatalogItem}" name="actionFuncToUpdate"/>
<input type="text" id="focusMe" style="display:none" />
<apex:commandButton onClick="callMyFunc();return false;" id="saveButton" value="Save" style="display:none"/>    

    <apex:pageBlockSection columns="2">
       <apex:outputField value="{!Portfolio_Catalog_Item__c.edit_Short_Name__c}">
             <apex:inlineEditSupport showOnEdit="saveButton, cancelButton" event="ondblclick" hideOnEdit="editButton, approveButton, deleteButton, cloneButton" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
        </apex:outputField>
    <apex:pageBlockSection columns="2">

Controller Extension:

public pageReference saveCatalogItem() {
       try {
           update currentCatalogItem;
       }
       catch(Exception e){
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, e.getMessage()));
       }
       return null;
}

Hope this helps.

0

The standard object below needs to be referenced in your save method -> or simply don't override the standard save method since you're using standardController and not doing anything special in your save method

    <apex:outputField value="{!Portfolio_Catalog_Item__c.edit_Short_Name__c}" />

Also - you could do this:

<apex:commandButton action="{!saveCatalogItem}" id="saveButton" value="Save" style="display: none" />
<apex:inlineEditSupport showOnEdit="saveButton, cancelButton" event="ondblclick" hideOnEdit="editButton, approveButton, deleteButton, cloneButton" changedStyleClass="myBoldClass" resetFunction="resetInlineEdit"/>
<apex:pageBlockSection columns="2">
    <apex:outputField value="{!catalogItem.edit_Short_Name__c}" />
</apex:pageBlockSection>

Controller:

public class MyController{

    public Portfolio_Catalog_Item__c catalogItem { get; set; }

    public MyController( ApexPages.standardController controller ){
          catalogItem = ( Portfolio_Catalog_Item__c )controller.getRecord();
    }

    public PageReference saveCatalogItem(){
        try{
            update catalogItem;
         }
         catch( Exception ex ){
             ApexPages.addMessage( new ApexPages.Message( ApexPages.Severity.ERROR, ex.getMessage() ));
         }

        return null;
    }

}

if you have a need to update this one item only and not the entire page - i can see the necessity to override the standard save method while doing no logic - as you would not be saving the entire page - however, given your example i don't really see that. simplest fix is just this:

I am also assuming that you're updating the rendered part of this button in JS code

<apex:commandButton value="Save" action="{!save}" style="display: none" />

You must log in to answer this question.

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