[SalesForce] Pass list values back to controller

I have the following code.

<apex:outputPanel id="deliveryRights" rendered="true">
<table id="table">
    <thead>
        <tr>
            <th>Category:</th>
            <th>Product:</th>
            <th>Details:</th>
            <th>Delivered:</th>
        </tr>
    </thead>
    <tbody>
        <apex:repeat value="{!RightsTrackerListDelivery}" var="O">
            <tr>
                <td>
                    <apex:inputField value="{!O.Category__c}"/>
                </td>
                <td>
                    <input type="text" value="{!O.Product__c}"/>
                </td>
                <td>
                    <input type="text" value="{!O.Details__c}"/>
                </td>
                <td>
                    <apex:inputField value="{!O.Delivered__c}"/>
                </td>
            </tr>
        </apex:repeat>
    </tbody>
</table>
<div>
    <apex:commandLink value="Add New Delivery Record" onClick="addTableRow();" id="addRowDelivery"/>
</div>

I have a list callled RightsTrackerListDelivery. When I edit the contents of the table I would like to be able to track the changes and update the rows dynamically.

I know this would be easier if I used an Apex component but I am forced to use a Apex repeat component.

I am using input fields to display the table data. I have the logic to add a new row but as for actually taking the new / editited values and passing them to the controller to update the list I'm a bit stuck.

Should I just loop though every cell, convert it all to a JSON object and pass it to the server?

Any ideas?

Best Answer

Since You are not aware of this. But if we use the apex:inputField in VF page then we can bind the data into list from Vf page

like

<apex:repeat value="{!mylist}" var="sobject">
     <apex:inputField value="{!sobject.Field1}" /> 
     <apex:inputField value="{!sobject.Field2}" /> 
  </apex:repeat>

This is will bind the value into your list. Whatever changes you made in this list, it will be binded into list and you can get those values in controller

so you need to perform update/ upsert DML on this list and everything should work fine

Related Topic