+ Start a Discussion
Joel RichardsJoel Richards 

Help with binding a checkbox value to a wrapper

Hi I have developed a visualforce page with a controller extension. That should allow the user to select a custom Object 'Territory_Account__c' for deletion (among other things) the problem is that the selected Territory Account is not returning True. The controller and visualforce page code is below. Any help would be great!

 

Page Controller:

public with Sharing class TerritoryController{
	
    ApexPages.StandardController con;
    public Territory__c Territory {get; set;}
    public List<TAWrapper> TAccounts {get;set;}
    private List<Territory_Account__c> TADeleteList = New List<Territory_Account__c>();
    private integer counter=0;  //keeps track of the offset
    public integer list_size=200; //sets the page size or number of rows
   	public integer total_size; //used to show user the total size of the list
    boolean DTA = False;
    Public Id TerritoryId;
    
    public TerritoryController(ApexPages.StandardController TController) {
    
      //  con = TController;
     //   Territory = (Territory__c)TController.getRecord();
        TerritoryId = ApexPages.CurrentPage().getParameters().get('id');
        
        total_size = [SELECT count() FROM Territory_Account__c WHERE Territory__c = :TerritoryId];
    }
    
    Public List<TAwrapper> getTAs() {	
        System.Debug('Joel: GetTAs has run');
        If(TAccounts == NULL) {
        	TAccounts = New List<TAWrapper>();
            For(Territory_Account__c TerAcc : [SELECT Id, Account__c, Account__r.name, Liberate_Cust_ID__c, Debtor_Group__c 
                                                   FROM Territory_Account__c 
                                                   WHERE Territory__c = :TerritoryId
                                                   ORDER BY Account__r.name
                                               	   LIMIT :list_size
                                                   OFFSET :counter])
                TAccounts.add(new TAWrapper(TerAcc,False));  
        } 
        return TAccounts;
    }
    

    Public class TAwrapper {

        Public TAwrapper(Territory_Account__c rTA, Boolean rSelected) {
            Selected = rSelected;
            TAccount = rTA;
        } 
        
        public Boolean Selected {get; set;}
        public Territory_Account__c TAccount {get; set;}
    }

    public PageReference DeleteTA() { 

        TADeleteList = New List<Territory_Account__c>();
        List<Id> TAIdList = New List<Id>();
        Territory_Account__c TAd;
	//	DTA = True;
        
    	For(TAWrapper TW : getTAs()) {
				System.debug('Joel: Print of TW '+TW);
                If(TW.Selected == True) {
                    System.Debug('Joel: TA is Selected');
                    TAIdList.Add(TW.TAccount.Id);
                }
            }
        
        If(TAIdList.Size()>0) { 
            For(Territory_Account__c Tac : [Select Id from Territory_Account__c where Id IN :TAIdList])
            	TADeleteList.Add(Tac);
            Delete TADeleteList;
            DTA = False;
         //   TAccounts = NULL;
            return NULL; //new PageReference(ApexPages.currentPage().getUrl());
        }
        else {
            System.Debug('Joel: TAdelete list is empty');
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'No Territory Accounts Selected'));
            DTA = False;
            Return Null;
        }       
              
      	
   	}

 The Visualforce Page:

<apex:page standardController="Territory__c" extensions="TerritoryController">
    <apex:sectionHeader title="Territory" subtitle="{!Territory__c.Name}"/>
    <apex:pageMessages />
    <apex:detail subject="{!$CurrentPage.parameters.id}" relatedList="false" title="false"/> 
    
    <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js"/>
    <script type="text/javascript">
        jQuery.noConflict();        
        $j = jQuery;
        
        $j( function(){
            $j("input.SelectAll").click(function(event){                
                $j("table.AccountsTable input[type=checkbox]").attr("checked", event.target.checked);
            });
        
        });        
    </script>
     
    <apex:pageBlock Title="Territory Accounts">
		<apex:pageBlockButtons location="top" >
   			<apex:outputPanel id="myButtons">
                <apex:form >
                    <apex:commandButton action="{!NewTA}" title="New Territory Account" value="New Territory Account" style="font-size:x-small;"/>
                    <apex:commandButton action="{!DeleteTA}" title="Delete Territory Account" value="Delete Territory Account" style="font-size:x-small;"/><br/>
                 <!--   <apex:commandButton action="{!Beginning}" title="Beginning" value="First Page" disabled="{!disablePrevious}" reRender="myPanel,myButtons" style="font-size:xx-small;"/>
                    <apex:commandButton action="{!Previous}" title="Previous" value="Previous Page" disabled="{!disablePrevious}" reRender="myPanel,myButtons" style="font-size:xx-small;"/>        
                    <apex:commandButton action="{!Next}" title="Next" value="Next Page" disabled="{!disableNext}" reRender="myPanel,myButtons" style="font-size:xx-small;"/>
                    <apex:commandButton action="{!End}" title="End" value="Last Page" disabled="{!disableNext}" reRender="myPanel,myButtons" style="font-size:xx-small;"/>   -->
               </apex:form>
       		</apex:outputPanel>
   		</apex:pageBlockButtons>
        
        <apex:outputPanel id="myPanel">
            <apex:form >
                <apex:outputPanel rendered="{!total_size > list_size}" style="color:red;">
                    <apex:outputText value="{0,number,###0}"><apex:param value="{!total_size}" /></apex:outputText>
                    results found,&nbsp;  
                    <apex:outputText value="{0,number,###0}"><apex:param value="{!list_size}" /></apex:outputText>
                    displayed per page<br/> 
                </apex:outputPanel>
                <apex:outputPanel rendered="{!total_size>list_size}">
                    Go to page: &nbsp;&nbsp;
                    <apex:commandLink action="{!page1}" value="1" rendered="{!AND(counter!=0,total_size>list_size)}" rerender="myPanel,myButtons"/>
                    <apex:outputText value="1" rendered="{!AND(counter==0,total_size>list_size)}" style="color:#666666;"/>
                    &nbsp;&nbsp;
                    <apex:commandLink action="{!page2}" value="2" rendered="{!AND(OR(counter<list_size,counter>=(list_size*2)),total_size>(list_size))}" rerender="myPanel,myButtons"/>
                    <apex:outputText value="2" rendered="{!AND(counter>=list_size,counter<(list_size*2),total_size>(list_size))}" style="color:#666666;"/>
                    &nbsp;&nbsp;
                    <apex:commandLink action="{!page3}" value="3" rendered="{!AND(counter<(list_size*2),total_size>(list_size*2))}" rerender="myPanel,myButtons"/>
                    <apex:outputText value="3" rendered="{!AND(counter>=(list_size*2),counter<(list_size*3),total_size>(list_size*2))}" style="color:#666666;"/>
                    &nbsp;&nbsp;
                    <apex:commandLink action="{!page4}" value="4" rendered="{!AND(counter<(list_size*3),total_size>(list_size*3))}" rerender="myPanel,myButtons"/>
                    <apex:outputText value="4" rendered="{!AND(counter>=(list_size*3),counter<(list_size*4),total_size>(list_size*3))}" style="color:#666666;"/>
                    &nbsp;&nbsp;
                    <apex:commandLink action="{!page5}" value="5" rendered="{!AND(counter<(list_size*4),total_size>(list_size*4))}" rerender="myPanel,myButtons"/>
                    <apex:outputText value="5" rendered="{!AND(counter>=(list_size*4),counter<(list_size*5),total_size>(list_size*4))}" style="color:#666666;"/>
                </apex:outputPanel>
    	
            	<apex:pageblockTable styleClass="AccountsTable" id="accounts-table" value="{!TAs}" var="TA" >
            		<apex:column style="width:60px;">
                  		<apex:facet name="header">
                    		<input type="checkbox" class="SelectAll"/>Action                  
                  		</apex:facet>            
                        <apex:inputCheckbox value="{!TA.Selected}"/>   
            		</apex:column>
                    <apex:column value="{!TA.TAccount.Account__c}" />
                    <apex:column value="{!TA.TAccount.Liberate_Cust_ID__c}"/>
                    <apex:column value="{!TA.TAccount.Debtor_Group__c}"/>
    			</apex:pageblockTable>
            </apex:form>
        </apex:outputPanel>
    </apex:pageBlock>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
AmitdAmitd

Hi Joeler,

 

Actually you have used two forms on your VF page. One for button section and one for pageBlockTable. You need to use one common form.

 

 

Please put your pageblock in one form tag and remove other form tags(used for buttons and table).

 

Hope this can help you.

 

If this work for you please mark this solution as resolved.

Kudos

 

 

 

 

Salesforce Developer, Salesforce Administrator

All Answers

AmitdAmitd

Hi Joeler,

 

Actually you have used two forms on your VF page. One for button section and one for pageBlockTable. You need to use one common form.

 

 

Please put your pageblock in one form tag and remove other form tags(used for buttons and table).

 

Hope this can help you.

 

If this work for you please mark this solution as resolved.

Kudos

 

 

 

 

Salesforce Developer, Salesforce Administrator

This was selected as the best answer
Joel RichardsJoel Richards

Thanks Amitd, that was the problem... I appreciate your help