You need to sign in to do that
Don't have an account?

Sending inputCheckBox values to controller
My code works like this. I have n number of Lead objects. When I click a checkbox I am trying to pass the value to a javascript function. It is not working. Any help. Also How do i achieve this functionality?
<apex:page controller="registerDomainController" tabStyle="Lead">
<script>
function addUsers(userid)
{
var idsToAdd = new Array();
alert('Before adding' + userid);
idsToAdd.add(userid);
}
</script>
<apex:sectionHeader title="Add User">
<apex:form>
<apex:pageBlock>
<apex:facet name="footer">
<apex:pageBlockSection title="Add Users to the Extranet">
<apex:dataTable value="{!allLeads}" var="user" cellspacing="0" cellpadding="4" border="0" width="800px">
<apex:column>
<apex:facet name="header">First Name</apex:facet>
<apex:outputText>{!user.firstname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Last Name</apex:facet>
<apex:outputText>{!user.lastname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Email Address</apex:facet>
<apex:outputText>{!user.email}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Phone number</apex:facet>
<apex:outputText>{!user.phone}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Add User</apex:facet>
<apex:inputCheckbox value="{!user.id}" onclick='addUsers({!user.id})'/>
</apex:column>
</apex:dataTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:sectionHeader>
</apex:page>
<apex:page controller="registerDomainController" tabStyle="Lead">
<script>
function addUsers(userid)
{
var idsToAdd = new Array();
alert('Before adding' + userid);
idsToAdd.add(userid);
}
</script>
<apex:sectionHeader title="Add User">
<apex:form>
<apex:pageBlock>
<apex:facet name="footer">
<apex:pageBlockSection title="Add Users to the Extranet">
<apex:dataTable value="{!allLeads}" var="user" cellspacing="0" cellpadding="4" border="0" width="800px">
<apex:column>
<apex:facet name="header">First Name</apex:facet>
<apex:outputText>{!user.firstname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Last Name</apex:facet>
<apex:outputText>{!user.lastname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Email Address</apex:facet>
<apex:outputText>{!user.email}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Phone number</apex:facet>
<apex:outputText>{!user.phone}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Add User</apex:facet>
<apex:inputCheckbox value="{!user.id}" onclick='addUsers({!user.id})'/>
</apex:column>
</apex:dataTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:sectionHeader>
</apex:page>
Hi Jason,
I am working on the functionality of checkbox in datatable. On clicking the checkbox,I have to retrive the value of corresponding row.I have aceive this functionality by using wrapper class.
Is this possible to acieve the functionality without using wrapper class.
Can you please help.
All Answers
onclick='addUsers({!user.id})'
if you think about what this will turn into once the formula is evaluated you'll see what I mean:
onclick='addUsers(005xxxxxxxx)'
so you need it to look like this:
onclick="addUsers('{!user.id}')"
which will result in the correct expansion:
onclick="addUsers('005xxxxxxx')"
NOTE: there is a bug w.r.t. handling of single quotes for attribute values that we've fixed in the next release but for now stick to using double quotes to delimit attribute values.
Also, the use of apex:outputText with child {!}'s is superflous and will result in a compile time validation error in an upcoming release. Either drop the outputText's all together and just use the {!} alone (my recommendation unless you need to force expression results to not be escaped which is unwise from a XSS vulnerability perspective) or use the soon to be required <apex:outputText value> attribute like this:
<apex:outputText value="{!user.name}"/>
Message Edited by dchasman on 03-11-2008 08:58 PM
Message Edited by dchasman on 03-12-2008 08:54 AM
dchasman wrote:
I'll work up an example and post it here soon.
I would be very interested in this as well. Would this example be a dataTable with check boxes next to records (rows) and then based upon which records are checked you can perform some type of logic on the selected rows? Essentially, as they are checked and unchecked they are inserted and removed automatically from a object list in the controller?
I looked for something like this in the documentation but could find it. This type of example would be money.
Message Edited by TehNrd on 03-12-2008 12:29 PM
I want a dataTable or a pageDataList with check boxes next to records (rows) and then based upon which records are checked I want to send the values of the checked records to my custom controller. My custom controller takes all the records, creates an XML and send the XML to an outside server.
Creating an XML and sending it to the server is done. I just need to collate all the values checked(checkboxes) by the user.
- create a small apex class wrapper around each sobject that mixes in your additional properties /or actions:
public class LeadWrapper {
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;
}
private final Lead delegate;
private boolean sendToExternalService;
}
- return a list of wrapped objects deom your controller's getter (getAllLeads() in this case)
VF data binding will now handle all the to and from bits and by the time your controller's sendToExternalService() action method is called you will have a collection of LeadWrapper objects that can each answer the "should I be sent the external service" question.
Message Edited by dchasman on 03-14-2008 08:44 AM
I have few questions. When will I call SendToExternalService? How to I get the value in testController?? I mean on click of the commandButton I call a method called testSaveUsers. How do the method testSaveUsers in my controller class get the values.
Please help!!!!
My first Page:
<apex:page controller="testController" tabStyle="Lead">
<apex:sectionHeader title="Add User">
<apex:form>
<apex:commandButton action="{!testSaveUsers}" value="Add User" styleClass="btn" ></apex:commandButton>
<apex:pageBlock>
<apex:pageBlockSection title="Add Users to the Extranet">
<apex:dataTable value="{!allLeads}" var="user" cellspacing="0" cellpadding="4" border="0" width="800px">
<apex:column>
<apex:facet name="header">First Name</apex:facet>
<apex:outputText>{!user.lead.firstname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Last Name</apex:facet>
<apex:outputText>{!user.lead.lastname}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Email Address</apex:facet>
<apex:outputText>{!user.lead.email}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Phone number</apex:facet>
<apex:outputText>{!user.lead.phone}</apex:outputText>
</apex:column>
<apex:column>
<apex:facet name="header">Add User</apex:facet>
<apex:inputCheckbox value="{!user.lead.id}" /> should I be using the onSelect={user.sendToExternalService}
</apex:column>
</apex:dataTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:sectionHeader>
</apex:page>
************************************************************************************
Figured it out. Thanks a ton for the help.
Regards
surjendu
I would also recommend using the SRC functionality when replying with code. That way it won't get all garbled. When typing a reply it is the button that says SRC.
Message Edited by TehNrd on 03-14-2008 02:09 PM
Could I get some more pointers/instructions of how I could add a check box in a contact dataTable and then have this reflected in my collection of contacts in the controller. Here is what I've got so far which is only a super simple controller and a dataTable.
Page:
Controller:
Thanks,
Jason
Message Edited by TehNrd on 03-18-2008 03:27 PM
My page has two lists (pageBlockLists) - contacts on the top and activities on the bottom. The goal is that when the checkboxes are selected on the contacts, the bottom pageBlock with the activities re-renders showing activities for all of the selected contacts. I am struggling to get the selected status back to the controller. The re-render is intended to be an ajax action triggered by the clicking of the checkbox - no submit button.
I've created a wrapper class to contain the contact plus the selected status, but can't seem to get the checked status of the checkbox back to the controller automatically. Using the onchange event of the checkbox I can fire actionsupport or actionfunction and get the re-render to happen, but not with an updated list of contacts.
I think I'm probably missing something pretty obvious - anybody help me out with the best way of doing this?
Here's my relevant code:
wrapper class: (note: still on spring 08)
relevant parts of the controller:
Any suggested solution?
If CampaignMember was first-class object, I won't have to worry about this implementation.
Can you please post your solution, I have a very similar issue.
Thanks,
shamil
Hi Jason,
I am working on the functionality of checkbox in datatable. On clicking the checkbox,I have to retrive the value of corresponding row.I have aceive this functionality by using wrapper class.
Is this possible to acieve the functionality without using wrapper class.
Can you please help.
Regarding this issue. I am trying to perform this logic to refresh a checkbox based on specific selected filter values.
I am waiting from anyone to answer this question regardless the @kmccoll and @TehNrd. How to avoid this issue basically to have a Specific Salesforce Record based on the selection of the Product Checkbox.
Please, follwing is the related business scenario for this issue:
I have two table primary and secondary. I want to retrieve the Product Info from primary table and show from secondary table. The Wrapper logic is completed, however, I need to display multiple selection based on one or more Products. Here is the Partial visualforce page and the apex method.
Apex method:
Any ideas to complet this issue.
Thanks in advance.