function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SurjenduSurjendu 

Options available if dont want to use SelectCheckBoxes

The reason I dont want to use SelectCheckBox  because I am not able to apply CSS on the SelectOptions. So I want to create a pageBlockList with relevant data for each record and
a checkbox for each record(for insert or delete the individual record).

If I do not want to use SelectCheckBox control of VisualForce and instead want to an iteration of checkboxes. Example

I have n records which are dynamic. That means I do not know how many records will be there. Its database driven.

UserName1      Email1      Phone1    CheckBox1
UserName2      Email2      Phone 2   CheckBox2
UserName3      Email3      Phone3    CheckBox3
...................       ...........      ...........     ....................

In this case how do I find out which of the checkboxes are selected. And how do I send the array of selected checkboxes to the controller?
Can I use javascript? If yes, plz send me some code snippets.
TehNrdTehNrd
I think dchasman is going to anwer the question about passing checked records in a data table to the controller in this post using standard VF functionality. I am interested in this as well.

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=691

-Jason



Message Edited by TehNrd on 03-12-2008 10:47 AM
SurjenduSurjendu
Code:
Say this is your VisualForce page:SaveUsers method will called when checkboxes are clicked and 
the command button is hit.

<apex:pageBlockButtons>
<apex:commandButton action="{!saveUsers}" value="Add User">
</apex:commandButton>
</apex:pageBlockButtons>



<apex:pageBlockList value="{!allLeads}" var="user" cellspacing="0" cellpadding="4"columns="4" columnswidth="400px,400px,400px,400px">

<apex:column headerValue="First Name">
<apex:outputText value="{!user.lead.firstname}"/>
</apex:column>

<apex:column headerValue="Last Name">
<apex:outputText value="{!user.lead.lastname}"/>
</apex:column>

<apex:column headerValue="Phone Number">
<apex:outputText value="{!user.lead.phone}"/>
</apex:column>

<apex:column headerValue="Email">
<apex:outputText value="{!user.lead.email}"/>
</apex:column>

<apex:column headerValue="Add User">
<apex:inputCheckbox value="{!user.sendToExternalService}"/>
</apex:column>

</apex:pageBlockList>

This is your controller class. Only relevant portion has been pasted.

List<LeadWrapper> listOfLeadWrappers = new List<LeadWrapper>();
List<LeadWrapper> selectedLeadWrappers = new List<LeadWrapper>();


public List<LeadWrapper> getAllLeads()
{
//Lead[] allLeads = [select id,firstname,lastname,email,phone from Lead];
for(Lead l : listOfSearchedLeads)
{
LeadWrapper wrapper= new LeadWrapper(l);
listOfLeadWrappers.add(wrapper);
}
return listOfLeadWrappers;
}

public List<String> getSelectedLeadWrappers()
{
List<String> listOfSelectedUsers = new List<String>();
for(LeadWrapper lw : listOfLeadWrappers)
{
if(lw.getSendToExternalService())
{
Lead l = lw.getLead();
listOfSelectedUsers.add(l.id);
}
}
return listOfSelectedUsers;
}


public PageReference saveUsers()
{
//Here the getSelectedLeadWrappers() will only give u the selected leadwrappers.
//The data binding has taken care of the selected checkboxes.
String[] listOfSelectedUsers = getSelectedLeadWrappers();



This is the LeadWrapper Class:

public class LeadWrapper
{
private final Lead delegate;
private boolean sendToExternalService;

public LeadWrapper(Lead delegate)
{
this.delegate = delegate;
}
public Lead getLead()
{
return delegate;
}
public void setSendToExternalService(boolean sendToExternalService)
{
this.sendToExternalService = sendToExternalService;
}
public boolean getSendToExternalService()
{
return sendToExternalService;
}
}


Plz let me know if u have any more questions.

 

TehNrdTehNrd
Thanks. That helps alot.