1

I have an <apex:inputField> in my visualforce page that controls a custom wrapper object which the user can update and then saves using <apex:commandButton> to my controller. The problem is the field that is supposed to be updated by the user is not reflected in the controller.

Here's the relevant part of the code:

Visualforce Page:

<apex:form id="salesRepForm">
<apex:pageBlock id="srTargetBlock">
    <apex:pageBlockButtons >
        <!-- THE BUTTON USED -->
        <apex:commandButton action="{!quickSaveSRTargets}"
            value="{!$Label.EUR_CRM_Quick_Save }" reRender="salesRepForm" status="loadingStatus" />
    </apex:pageBlockButtons>
    <apex:pageBlockSection columns="1">
        <apex:pageblockTable value="{!SalesRepAndSalesAgencyTargetWraps}" var="srTargetWrap" id="srTargetTable">
            <apex:column >
                <table width="100%">
                    <apex:repeat value="{!srTargetWrap.srTargets}" var="srTarget">
                        <tr>
                            <td width="60%"><apex:outputField value="{!srTarget.EUR_CRM_Target_Owner__c}" /></td>
                            <td width="40%">
                                <!-- THE INPUT FIELD IN QUESTION -->
                                <apex:inputField styleClass="srTarget"
                                    value="{!srTarget.EUR_CRM_Qty_Sell_in_Amount_Bottle__c}"
                                    style="text-align:right" rendered="{!isDraft}" />
                            </td>
                        </tr>
                    </apex:repeat>
                </table>
            </apex:column>
        </apex:pageblockTable>
    </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

Wrapper Class:

public class TargetWrap{

    public EUR_CRM_ObjPromo_Target__c target{get;set;}
    public List<EUR_CRM_ObjPromo_Target__c> srTargets{get;set;}

    public TargetWrap(List<EUR_CRM_ObjPromo_Target__c> srTargets, EUR_CRM_ObjPromo_Target__c target){
        this.target= target;
        this.srTargets = srTargets;
    }
}

Controller:

public List<TargetWrap> salesRepTargetWrap {get; set;}

public List<TargetWrap> getSalesRepAndSalesAgencyTargetWraps(){ 
    salesRepTargetWrap = new List<TargetWrap>();
    // Retrieves relevant data and construct a list of Wrapper Class
    salesRepTargetWrap.addAll(retrieveRelevantData());    

    return salesRepTargetWrap;
}

Save method in the controller:

public PageReference quickSaveSRTargets() {
    // TODO: SalesRepTargetWrap are not updated from the VF Page
    if(salesRepTargetWrap != null && salesRepTargetWrap.size() > 0) {

        // BUG BELOW
        System.debug(salesRepTargetWrap); // EUR_CRM_Qty_Sell_in_Amount_Bottle__c is not updated for all elements in the Wrapper list

        // ...
        // Additional logic to upsert records

        upsert newSRTargets;
    }

    return refresh();
}

Furthermore, the UI looks like the image below. Any value put in the input field (and pressing Quick Save button) will not be reflected in the controller (as shown by System.debug statements in the controller). UI

Any suggestions or guidance will be accepted! Thanks.

  • You have used rendered attribute for the inputField, so some records won't be available to edit – highfive Mar 30 '16 at 4:30
  • Unfortunately that is not the case, since those inputField are actually rendered on the page. I have edited the post to include the UI (see the attached picture). Thanks anyway. – bwgenio Mar 30 '16 at 5:28
0

I already resolved this problem by integrating getSalesRepAndSalesAgencyTargetWraps() with the wrapper's getter function in the controller.

I think the problem happens because the list returned from the actual get; getter (called from the controller when saving) and getSalesRepAndSalesAgencyTargetWraps() (called from the UI when rendering) might not be the same instance, hence why modifying them in the UI doesn't reflect to the controller.

Here's the modified controller:

public List<TargetWrap> salesRepTargetWrap {
    get {
        salesRepTargetWrap = new List<TargetWrap>();
        // Retrieves relevant data and construct a list of Wrapper Class
        salesRepTargetWrap.addAll(retrieveRelevantData());    

        return salesRepTargetWrap;          
    }

    set;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.