0

I am creating rows dynamically in my vf page.. In that row i have two picklist fields and 7 text fields.. I want when i will press copy commandlink the values from previous rows will get copied to the current one.

On initial page load , 5 rows default is created..

Hence i am finding difficult how to find which row index i need to copy..

Can anybody share some examples..

I have kept evrything in a wrapper class..Below is my controller. I need a method for copyrow values.

<apex:commandLink value="Copy" action="{!cloneWrappeer}" reRender="pb">
                            <apex:param assignTo="{!chosenRow}" name="chosenRow" value="{!acc.index}"/>
                            </apex:commandLink>

acc - is my wrapper class var in pageblocktable.. Custom_Package__c is my object and i have field like -

Name - Market - State -

attendeeList1 - Wrapper class instance..How to copy the fields..

 public void cloneWrappeer(){

        for ( Integer i = 0; i < attendeeList1.size(); i++ ) {


    }
}
2
  • Paste your VF page, that would help. Nov 18, 2015 at 13:04
  • If you solve the proble then close the question, or mark as solve.
    – Torsen
    Nov 23, 2015 at 9:02

1 Answer 1

0

I have added snippets below that will do what you need. I have included VF markup for a column in an apex:pageblocktable, id=units, with a commandlink and param attribute; also a snippet of apex code to copy the data from one row to the others. I am presuming that the blank rows already exist in a collection. In this case my collection is called units and the object type is Unit__c - obviously change as necessary.

VF:-

<apex:column rendered="false">
   <apex:commandLink value="Copy to other rows" action="{!copyRow}" reRender="units">
   <apex:param assignTo="{!chosenRow}" name="chosenRow" value="{!unit.id}"/>

   </apex:commandLink>

Apex:-

public list<Unit__c> units{get; set;}

    public id chosenRow{get; set;}
public void copyRow(){

//      system.debug(chosenRow);

        Unit__c chosenUnit;


        for(Unit__c unit : units){

            if(unit.id == chosenRow){
                chosenUnit = unit;
                break;
            }
        }
        for(Unit__c unit : units){
            unit.field_1__c = chosenUnit.field_1__c;
            unit.field_2__c = chosenUnit.field_2__c;
            ...


        }
        chosenRow = null;
    }
5
  • Hi Richard...How this can be achieved if we have dynamic row creation.. There we need to check row index to copy.. Nov 23, 2015 at 10:33
  • in your wrapper class set an identifier and use that inplace of the unit.id in the param in the VF page Nov 23, 2015 at 11:56
  • Richard.. Do u have any example.. Nov 23, 2015 at 12:02
  • I don't have an example but in the wrapper add an ' public integer index{get; set;}' and populate with the instance number when you create your wrapper class and set the param to use this value. Use this value in your apex to get the correct row. Nov 23, 2015 at 12:06
  • Hi Richard.. I have updated my post.. Can u please chek.. Nov 23, 2015 at 12:38

You must log in to answer this question.

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