0

I have a little challenge which I'm trying, I want whenever the checkbox is checked I want to copy the values into input text fields in visualforce page.

So here I have multiple rows and corresponding to that I have checkboxes, Whenever I click a checkbox values should pass to input text fields.

For more understanding, I'm attaching the screenshot of challenge.

enter image description here

VISUALFORCE:

 <apex:pageBlockTable value="{!WrapperOrder}" onclick="insert_numbers()" var="or" id="pbtable">    
<apex:column headervalue="Batch Price and Quantity">
                         <apex:pageBlockTable value="{!or.batc}" var="ba" id="thispa">  
                             <apex:column headerValue="Price">
                                <apex:outputtext value="{!ba.Unit_Price__c}" />
                             </apex:column>   
                             <apex:column headerValue="Qty">
                                <apex:outputfield value="{!ba.Asked_Qty__c}" />
                             </apex:column>
                             <apex:column headerValue="Action" id="thiscol" >
                                <apex:inputCheckbox value="{!or.checkval}" >
                                <apex:actionSupport event="onclick" action="{!copyField}" reRender="pbtable" /> </apex:inputCheckbox><!-- pageblocktable Id is rendering -->
                             </apex:column> 
                       </apex:pageBlockTable>
                    </apex:column>
                 <apex:column headerValue="Unit Price"  >
                     <apex:inputField id="rpri" value="{!or.rorli.Price__c}" Style="width:50px" styleClass="spri" />
                 </apex:column>
                 <apex:column headerValue="Qty" id="col" styleClass="col" >
                     <apex:inputField id="rqty" value="{!or.rorli.Quantity__c}" Style="width:25px" styleClass="sqty" />
                 </apex:column> 
 </apex:pageBlockTable>

Apex code of that function:

public void copyField(){

             List<batch__c> batcj1=new list<batch__c>();

             //system.debug(LoggingLevel.Info,wrapperorder);

             for(WrapperOrderline wraporderObj :WrapperOrder) {


                    System.debug('Entered to the loop');
                    Map<string,List<batch__c>> mapq=new Map<string,List<batch__c>>();
                    system.debug(wraporderObj.rorli.Name);
                    mapq.put(wraporderObj.rorli.Name,wraporderObj.batc);
                    System.debug(mapq.keyset());
                    System.debug(mapq.values());
            // if(!mapq.containsKey(wraporderobj.rorli.Name)){              
               if(wraporderObj.checkval==true) {
                    System.debug('true');

                    wraporderObj .rorli.Price__c=wraporderObj.batc[1].Unit_Price__c;
                    String qtyc=wraporderObj.batc[1].Asked_Qty__c;
                    wraporderObj .rorli.Quantity__c=Integer.ValueOf(qtyc);
                }else{
                    wraporderObj .rorli.Price__c=null;
                    wraporderObj .rorli.Quantity__c=null;
                    System.debug('not selected true');
                    }
              } 

              //}
      }

Now what is happening with that code is whenever I true the checkbox it's not happening(means it's checking to the true state). When I check last checkbox in the row that will check all boxs to true and it will copy the data which is there in the memory location 1 of one in the list of the map. Here I want o know where I'm wrong, to get the proper result.

  • Instead of posting duplicate questions, please edit your existing post to add the details that were requested by community members. – David Reed Apr 29 at 13:15

Your Answer

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

Browse other questions tagged or ask your own question.