function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nellymnjnellymnj 

in-place editing does not work - please help

Hello,

i've created a VF page using

Example Code for In-Place Editing in Visualforce

for adding new items to Opportunity Inventory (Move_Inventory_Item__c is a custom object),

and it works fine if there are already Inventory Items added to this Opportunity, but if you try to add a first Item, page just does not do anything. Can anybody see what is wrong here? - thank you very much.

Here is the page:

<apex:page sidebar="false" controller="MoveInventoryController" tabStyle="Inventory_Item__c" action="{!init}" >
<style>
  .alphaOn{font-weight:bold;text-decoration:none;}
  .bPageBlock .pbTitle {width:100%;}
  .bPageTitle {margin-bottom:5px;}
  </style>
<apex:sectionHeader title="Manage Move Inventory" subtitle="{!Opp.Name}"/>
    <apex:outputPanel ><apex:outputLink value="/{!Opp.Id}">« Return to Opportunity</apex:outputLink></apex:outputPanel>
    <apex:pageMessages />
    <apex:form >
    <apex:pageBlock title="Add Non-Standard Inventory Item">
        Name:   <apex:inputField value="{!newItem.Name}"/>
        Size:   <apex:inputField value="{!newItem.Size__c}"/>  
        Weight:   <apex:inputField value="{!newItem.Weight__c}"/>
        Quantity:   <apex:inputField value="{!newItem.Quantity__c}"/>  
        <apex:commandButton value="Add" action="{!add}"/>
    </apex:pageBlock>
    </apex:form>
    <apex:form >
    <apex:pageBlock title="Existing Opportunity Inventory Items  - {!Opp.Volume2__c} cubic feet, {!Opp.Weight__c} lbs" id="inventoryTitle">
    <apex:outputPanel id="inventoryList">
    <table>
        <tr>
            <th style="width:20px"> </th>
            <th style="width:20px"> </th>
            <th style="width:140px">Name</th>
            <th style="width:50px">Size</th>
            <th style="width:50px">Weight</th>
            <th style="width:50px">Quantity</th>
            <th style="width:50px">Total Volume</th>
            <th style="width:50px">Total Weight</th>        
        </tr>
        <apex:repeat value="{!OppInventory}" var="it">
        <tr style="height:20px">
            <apex:outputPanel id="editRow" layout="none" rendered="{!it.Id == editItem.Id}">
                <td><apex:commandLink action="{!cancelEdit}" rerender="inventoryList">Cancel</apex:commandLink></td>
                <td><apex:commandLink action="{!saveEdit}" rerender="inventoryList">Save</apex:commandLink></td>
                <td><apex:inputText size="40" rendered="{!it.Id == editItem.Id}" onkeypress="if (event.keyCode == 13) saveEdit()"
                        value="{!editItem.Name}"/></td>
                <td><apex:inputField rendered="{!it.Id == editItem.Id}" value="{!editItem.Size__c}"/></td>
                <td><apex:inputField rendered="{!it.Id == editItem.Id}" value="{!editItem.Weight__c}"/></td>
                <td><apex:inputField rendered="{!it.Id == editItem.Id}" value="{!editItem.Quantity__c}"/></td>
            </apex:outputPanel>
            <apex:outputPanel id="viewRow" layout="none" rendered="{!it.Id != editItem.Id}">
                <td>
                    <apex:commandLink action="{!del}" onclick="return confirm('Are you sure you want to delete this item?')">Del
                        <apex:param name="delid" value="{!it.Id}"/>
                    </apex:commandLink>
                </td>
                <td>
                    <apex:commandLink action="{!edit}" rerender="inventoryList">Edit
                        <apex:param name="editid" value="{!it.Id}"/>
                    </apex:commandLink>
                </td>
                <td>{!it.Name}</td>
                <td>{!it.Size__c}</td>
                <td>{!it.Weight__c}</td>
                <td>{!it.Quantity__c}</td>
                <td>{!it.Cubic_Feet__c}</td>
                <td>{!it.Total_Weight__c}</td>
                
            </apex:outputPanel>
        </tr>
        </apex:repeat>
    </table>
    </apex:outputPanel>
    </apex:pageBlock>
</apex:form>

</apex:page>

 

and the controller:

 

public with sharing class MoveInventoryController {
    public Move_Inventory_Item__c newItem { get; set; }
    public Move_Inventory_Item__c editItem { get; set; }
    public Opportunity opp { get; set; }

    public MoveInventoryController() {
        newItem = new Move_Inventory_Item__c();
    }
    public PageReference init() {
        try{
            opp = [select Id, Name, Volume2__c, Weight__c
                    from Opportunity
                    where Id = :ApexPages.currentPage().getParameters().get('oppid') LIMIT 1];
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }    
        return null;
    }
    
    public Move_Inventory_Item__c[] getOppInventory() {
        return [select Id, Name, Size__c, Weight__c, Quantity__c, Cubic_Feet__c, Total_Weight__c, Opportunity__c
                    from Move_Inventory_Item__c
                    where Opportunity__c = :ApexPages.currentPage().getParameters().get('oppId')];
    }
    
    public String getParam(String name) {
        return ApexPages.currentPage().getParameters().get(name);    
    }
    
    public PageReference add() {
        try {
            newItem.Opportunity__c = ApexPages.currentPage().getParameters().get('oppId');
            INSERT newItem;
            // if successful, reset the new project for the next entry
            newItem = new Move_Inventory_Item__c();
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
        return null;
    }
    
    public PageReference del() {
        try {
            String delid = getParam('delid');
            Move_Inventory_Item__c item = [SELECT Id FROM Move_Inventory_Item__c WHERE ID=:delid];
            DELETE item;
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
        return null;
    }
    
    public PageReference edit() {
        String editid = getParam('editid');
        editItem = [SELECT Id, Name, Size__c, Weight__c, Quantity__c, Cubic_Feet__c, Total_Weight__c
            FROM Move_Inventory_Item__c WHERE Id=:editid];
        return null;
    }
    
    public PageReference cancelEdit() {
        editItem = null;
        return null;
    }
    
    public PageReference saveEdit() {
        try {
            UPDATE editItem;
            editItem = null;
        } catch (Exception e) {
            ApexPages.addMessages(e);
        }
        return null;
    }
}

bob_buzzardbob_buzzard

This indicates there's something going wrong in the add method.  I've seen problems using this method to add error messages:

 

 

        } catch (Exception e) {
            ApexPages.addMessages(e);
        }

 

Try adding an explicit message, e.g.

 

 

        } catch (Exception e) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'An error occurred adding the item'));
        }

 

Also, some System.debug statements would help you narrow down exactly what is going on.