+ Start a Discussion
SFDC_LearnerSFDC_Learner 

Custom Lookup with dynamic rows added

Hi

I am working on Custom lookup added multi rows when I clicked on "ADD" button.

I am able to work for first row, because I am assigning the value in javascript based on VF element Id.

But I need to do the same for multi lines, then finally for all the rows I need to collect the list of data to do DML.

Below are the sample I have written, but not able to complete the rest.

Please suggest me / send me your thoughts to do it.

Page1:

<apex:page controller="MultiLineCls" cache="true" id="pg">
    <script>
        function showpopup123(){
           var value1=window.showModalDialog('/apex/page2', '','dialogHeight=800px;dialogWidth=800px');
           document.getElementById('pg:fm:j_id2:0:name').value=value1;
          return false;
        }
    </script>
  <apex:form id="fm">
      <table>
           <apex:repeat value="{!lstC}" var="c">
              <tr><td><apex:inputtext value="{!c.lastName}" id="name"/></td><td>
                  <apex:commandLink >
                              <img src="/s.gif" alt="Parent Account Lookup (New Window)" class="lookupIcon" onblur="this.className = 'lookupIcon';" onfocus="this.className = 'lookupIconOn';" onmouseout="this.className =
   
    'lookupIcon';this.className = 'lookupIcon';" onmouseover="this.className = 'lookupIconOn';this.className = 'lookupIconOn';" title="Parent Account Lookup (New Window)" onclick="return showpopup123();"/>
                  </apex:commandLink>
                  </td>
              </tr>
           </apex:repeat>
      </table>
      <apex:commandButton value="ADD" action="{!doADD}" rerender="fm"/>
  </apex:form>
</apex:page>

Controller for the above Page:

public class MultiLineCls{
    public List<Contact> lstC{get;set;}
    public String lkupVal{get;set;}
    public MultiLineCls(){
        lstC = new List<Contact>();
        lstC.add(new Contact());
    }
   
    public pagereference doADD(){
       
        lstC.add(new Contact());
        return null;
    }
}



Lookup Page (page2)

<apex:page controller="GetAccounts" wizard="true">
    <script>
        function sendacc(accName,accId)
        {
            window.returnValue = accName+"#"+accId;
            self.close();
        }
    </script>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a">
                <apex:column headerValue="Account">
                    <a value="{!a.name}" onclick="sendacc('{!a.name}','{!a.Id}')">{!a.name}</a>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>


Thank you.
Ankit AroraAnkit Arora
You can use wrapper class for this. When you click on "Add" button, new instance of wrapper should be created in your controller which will keep the values for each row separate.

https://developer.salesforce.com/page/Wrapper_Class