0

I have a requirement where i have to pass the value of the selected check boxes to controller method.

enter image description here

i need to send the combination of values, i.e Auditoriums and Carpet to my controller. Can you please help here.

<apex:page standardController="Deal__c" extensions="RoomAndFloorTypesController" sidebar="false">
    <apex:form >

    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />

    <apex:commandButton value="Proceed with Selected" action="{!ProceedWithSelected}" reRender="panelId"/>
    <apex:pageBlock id="pageBlockId" >
        <apex:outputPanel id="panelId">
            <apex:pageblockTable value="{!wrapperList}" var="wrapRec" rendered="{!normalList}">
             <apex:column>
                 <apex:inputCheckbox id="val" value="{!wrapRec.selected}" onclick="callRoomType('Auditoriums');"/>
              </apex:column>
              <apex:column value="{!wrapRec.opp}"/>
            <apex:column >

                   <apex:selectList value="{!selected}" size="1" label="Account">
                   <apex:selectOptions value="{!picklst}"></apex:selectOptions>
                  </apex:selectList>     

               </apex:column>                     
           </apex:pageblockTable>



               <apex:pageblockTable value="{!selectedWrapperList}" var="wrapRec" rendered="{!selectedList}">

                   <apex:column value="{!wrapRec.opp}"/>
                   <apex:column >
                       <apex:inputCheckbox value="{!wrapRec.selected}"/>
                   </apex:column>
              </apex:pageblockTable>
            </apex:outputPanel>      
        </apex:pageBlock> 
        <apex:actionFunction action="{!sendRoomType}" name="sendRoomType" />
        <script type="text/javascript">

        function callRoomType(checkbox){
        alert('hi ='+document.getElementById("j_id0:j_id1:pageBlockId:j_id3:5:cb1").value);
        sendRoomType(room);

        }


        </script>

        <script>

            $(document).ready(function() {
        $('#callRoomType').change(function() {
            if ($(this).prop('checked')) {
                alert("You have elected to show your checkout history."); //checked
            }
            else {
                alert("You have elected to turn off checkout history."); //not checked
            }
        });
    });

        </script>

    </apex:form>
</apex:page>

Controller Class :

public class RoomAndFloorTypesController{

    public string selected{get;set;}

    List<SelectOption> valuesfrompicklist{get;set;}
    public RoomAndFloorTypesController(ApexPages.StandardController stdController){
        normalList = true;
        selectedList = false;
        fetchData();

    }
    public boolean normalList{get;set;}
    public boolean selectedList{get;set;}
    public Prodrate_Rooms__c prodRateObj{get;set;}

    public void fetchData(){
       List<Prodrate_Rooms__c > allOpps = [Select name,Id, Room__c, Flooring__c from Prodrate_Rooms__c];

        Set<string> parentIdSet = new Set<String>();
        //Create parent Id set 
        for(Prodrate_Rooms__c OppertunityRec :allOpps){
            parentIdSet.add(OppertunityRec.Room__c);
            system.debug('parentIdSet=='+parentIdSet);
        }

        wrapperList = new list<myWrapperClass>();
        //For loop to set data
        for(String childRec : parentIdSet){

            //Adding Opportunities without account
            if(childRec != null){
                    myWrapperClass wrapRec = new myWrapperClass();

                    wrapRec.opp = childRec;
                    wrapperList.add(wrapRec);

            }

        } 
    }
    public List<myWrapperClass> selectedWrapperList {get; set;}
    public void ProceedWithSelected(){
        selectedWrapperList = new List<myWrapperClass>();
        normalList = false;
        selectedList = true;
        for(myWrapperClass selectedWrapObj: wrapperList){
            system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selected);
            if(selectedWrapObj.selected == true)
            selectedWrapperList.add(selectedWrapObj);
        }
        system.debug('selectedWrapperList size ---------'+selectedWrapperList.size());
    }

    //Wrapper list 
    public List<myWrapperClass> wrapperList {get; set;}
    //Your wrapper 
    public class myWrapperClass{

        public String opp{get;set;}
        public Boolean selected {get; set;} 
        public myWrapperClass() { 
            selected = false; 
        } 
    }

    public List<SelectOption> getpicklst(){
        List<SelectOption> option=new List<SelectOption>();
        List<Prodrate_Rooms__c> acclst=[Select id,Room__c,Flooring__c from Prodrate_Rooms__c where Room__c='Auditoriums'];
        system.debug('acclst=='+acclst);


        for(Prodrate_Rooms__c ob:acclst){
            system.debug('ob=='+ob);
            option.add(new SelectOption(ob.id,ob.Flooring__c));
            system.debug('option inside loop=='+option);
        }
        return option;
    }

    public void sendRoomType(){
        system.debug('RoomType==');
        getpicklst();


    }

}
3

Create one more string variable in your wrapper class and bind that with your select List

public class myWrapperClass{

    public String opp{get;set;}
    public String selectedvalue{get;set;}
    public Boolean selected {get; set;} 
    public myWrapperClass() { 
         selected = false; 
      } 
}

Now update your selectList

<apex:selectList value="{!wrapRec.selectedvalue}" size="1" label="Account">
     <apex:selectOptions value="{!picklst}"></apex:selectOptions>
</apex:selectList>

Now you will get both value

for(myWrapperClass selectedWrapObj: wrapperList){
    system.debug('selectedWrapObj.selected  ---------'+selectedWrapObj.selectedvalue);
    if(selectedWrapObj.selected == true)
           selectedWrapperList.add(selectedWrapObj);
}

Currently you are binding it with single variable thats why you don't get correct value.

|improve this answer|||||
  • Thans for your reply. My requirement is to pass the value : Auditorium and Carpet. This combination of data should be saved and sent to next page based on which calculations will take place. i need to get the value dynamically of the checkbox and send to controller. As of now i am hardcoding. Please check below code : <apex:column > <apex:selectList value="{!selected}"> <apex:selectOptions value="{!picklst}"></apex:selectOptions> </apex:selectList> </apex:column> – user47646 Sep 8 '17 at 9:05
  • and then calling a javascript function function callRoomType(checkbox){ alert('hi'+document.getElementById("j_id0:j_id1:pageBlockId:j_id3:5:cb1").value); sendRoomType(rooom)}`` – user47646 Sep 8 '17 at 9:11
  • <apex:column> <apex:inputCheckbox id="val" value="{!wrapRec.selected}" onclick="callRoomType('Auditoriums');"/> </apex:column> – user47646 Sep 8 '17 at 9:13
  • @user47646 Did you read my answer? check my last for loop there you will get all selected value with related picklist value as well. – Tushar Sharma Sep 8 '17 at 9:20

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.