You need to sign in to do that
Don't have an account?
Matias Ramirez 2
Change checkbox by radioButton in a VFP
Hello everyone.
I need to process a selected row in a table in a VFP, let's say I need to show what is selected.
I can do it with Checkboxes, but I need to do it with RadioButtons (only one row should be checked at time)
I wanted to know if it is possible to achive this with Apex.
This is what I've done:
VFP
And this is the controller:
I need to process a selected row in a table in a VFP, let's say I need to show what is selected.
I can do it with Checkboxes, but I need to do it with RadioButtons (only one row should be checked at time)
I wanted to know if it is possible to achive this with Apex.
This is what I've done:
VFP
<apex:page controller="showContactsCtrl"> <apex:form > <apex:pageBlock> <apex:pageBlockTable value="{!contactsWrapList}" var="contactVariable" > <apex:column onclick="{!contactVariable.selected}"> <apex:inputCheckbox value="{!contactVariable.selected}" id="CheckBox" onclick="SelectedOne(this)" > </apex:inputCheckbox> </apex:column> <apex:column value="{!contactVariable.c.name}"/> </apex:pageBlockTable> </apex:pageBlock> <apex:commandButton action="{!m1}" value="Select Contact" /> </apex:form> <apex:outputPanel> <p>You have selected:</p> <apex:dataList value="{!selectedContact}" var="c">{!c}</apex:dataList> </apex:outputPanel> </apex:page>
And this is the controller:
public class showContactsCtrl { public List<Contact> contacts; public List<contactsWrap> contactsWrapList {get; set;} public String selectedContact {get; set;} public showContactsCtrl(){ contacts = [SELECT Id, Name FROM Contact WHERE Account.Id = someAccountId]; contactsWrapList = new list<contactsWrap>(); for(Contact c : contacts){ contactsWrapList.add(new contactsWrap(false, c)); } } public void m1(){ for(contactsWrap contactsWrapObj : contactsWrapList) { if(contactsWrapObj.selected) selectedContact = contactsWrapObj.c.Name; } } public class contactsWrap{ public Contact c {get; set;} public boolean selected{get; set;} public contactsWrap(Boolean s, Contact param){ this.c = param; selected = s; } } }
Greetings to you!
Please refer to the below links which might help you further with the above requirement.
https://readsalesforce.wordpress.com/2018/04/12/radio-button-with-records-in-pageblocktable-visualforce-page-salesforce-com-basics/
https://developer.salesforce.com/forums/?id=9060G000000I3vJQAS
http://www.infallibletechie.com/2012/07/radio-button-in-salesforce.html
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Greetings to you!
Please refer to the below links which might help you further with the above requirement.
https://readsalesforce.wordpress.com/2018/04/12/radio-button-with-records-in-pageblocktable-visualforce-page-salesforce-com-basics/
https://developer.salesforce.com/forums/?id=9060G000000I3vJQAS
http://www.infallibletechie.com/2012/07/radio-button-in-salesforce.html
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Please try the below code and let me know if this works for you. If still need modifications do let me know.
VF Page :
<apex:page controller="showContactsCtrl">
<apex:slds />
<apex:form >
<apex:pageBlock>
<apex:pageBlockTable value="{!contactsWrapList}" var="contactVariable" >
<apex:column onclick="{!contactVariable.selected}">
<input type="radio" value="{!contactVariable.selected}" id="CheckBox" name="rasio" onclick="SelectedOne(this)" />
</apex:column>
<apex:column value="{!contactVariable.c.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:commandButton action="{!m1}" value="Select Contact" />
</apex:form>
<apex:outputPanel>
<p>You have selected:</p>
<apex:dataList value="{!selectedContact}" var="c">{!c}</apex:dataList>
</apex:outputPanel>
</apex:page>
Controller :
public class showContactsCtrl {
public List<Contact> contacts{get;set;}
public List<contactsWrap> contactsWrapList {get; set;}
public String selectedContact {get; set;}
public showContactsCtrl(){
contacts = [SELECT Id, Name FROM Contact WHERE Account.Id =: '0010o00002CgszDAAR'];
contactsWrapList = new list<contactsWrap>();
for(Contact c : contacts){
contactsWrapList.add(new contactsWrap(false, c));
}
}
public void m1(){
for(contactsWrap contactsWrapObj : contactsWrapList) {
if(contactsWrapObj.selected)
selectedContact = contactsWrapObj.c.Name;
}
}
public class contactsWrap{
public Contact c {get; set;}
public boolean selected{get; set;}
public contactsWrap(Boolean s, Contact param){
this.c = param;
selected = s;
}
}
}
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
Greetings to you!
- I read your problem and implemented in my Org.
- Please use the below code [Solved] : -
VF page : -
Class : -
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha.