+ Start a Discussion
Shwetal DesaiShwetal Desai 

Pass selected Checkbox values in Controller

I have one visualforce page with PageBlockTable
A List of SOBject in custom controller gives value to that pageBlockTable
Now i have created one column with <apex:inputCheckbox> in same pageBlockTable
 
Now i want the List of selected rows of that pageblocktable and need to save that list in a custom object.
 
How can i perform this task?
Here is my code:
VF Page Code:
<apex:page controller="viewhold" showHeader="false" tabStyle="POS__c">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
    <apex:commandButton id="btnRestore" value="Restore"/>
    <apex:commandButton id="btnCombine" value="Combine"/>
    <apex:commandButton id="btnCancel" value="Cancel"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!HoldPos}" var="pos">
    <apex:column >
    <apex:facet name="header">Select</apex:facet>
    <apex:inputCheckbox value="{!pos.Id}" /> 
    </apex:column>
    
    <apex:column value="{!pos.Name}"/>
    <apex:column value="{!pos.Client__r.Client__c}"/>
    <apex:column value="{!pos.CreatedDate}"/>
    <apex:column value="{!pos.TotalDue__c}"/>
    <apex:column value="{!pos.TotalPaid__c}"/>
</apex:pageBlockTable>   
</apex:pageBlock>
</apex:form>
</apex:page>
Code:
public class viewhold 
{
List<POS__c> poslist = new List<POS__c>();
List<POS__c> selectedpos = new List<POS__c>();

    public List<POS__c> getHoldPos()
        {
                poslist = [select id,Name,Client__r.Id,Client__r.Client__c,CreatedDate,RetailAmt__c,ServiceAmt__c,TotalDue__c,TotalPaid__c from POS__c where Status__c='Hold' and Client__c =: System.CurrentPageReference().getParameters().get('cid')];
                return poslist;
        }       
    public void Addticket()
    {
        for(POS__c pos:poslist)
        {
            selectedpos.add(pos);
        }    
    }
}

 Please let me know where m doing mistakes?
and what should i do to perform this task??
 
Thanks.
TehNrdTehNrd
This thread address the issue you are facing and has some great examples...

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=756
Shwetal DesaiShwetal Desai

Thanks Jason,

I have gone through that Thread address

but to be very honest with you still i m not able to understand that how can i get bunch of rows which are selected by user ?

As i need to save that rows in my custom object by overriding Save() operation in a controller.

Can you guide me more?

waiting for reply / Help.



Message Edited by Shwetal Desai on 09-25-2008 06:30 AM
Amita TatarAmita Tatar
Hi shweta,

I have similar requirement as that of yours. How youn achieved it ? Can you help me?