You need to sign in to do that
Don't have an account?
Trying to pass parameters to controller class from <input type = "Radio">
Hello Community,
I am trying to create a Visualforce page that has single-select radio button in front of every record. When user selects a particular record's radio button and clicks create task, it creates a task and associates it with the corresponding Account. So far i am not able to figure out why it is not working. My guess is that the parameters are not able to travel from page to class method. Please help! Code below:
Visualforce Page: <apex:page controller="AccountTask"> <apex:form > <apex:pageBlock title="Page that creates Tasks"> <apex:pageBlockTable value="{!Acclist}" var="ac"> <apex:column value="{!ac.name}" id="name"/> <apex:column value="{!ac.phone}"/> <apex:column value="{!ac.type}"/> <apex:column value="{!ac.SLAExpirationDate__c}"/> <apex:column headerValue="Select to Create Task" id="task"> <apex:actionSupport event="onclick" rerender="pbs2"> <input type="radio" name = "newselect"> <apex:param name="SelectedAccountId" value="{!ac.Id}"/> <apex:param name="SelectedAccountName" value="{!ac.name}"/> </input> </apex:actionSupport> </apex:column> <apex:column headerValue="Action"> <apex:commandButton value="Create Task" action="{!CreateTask}"/> </apex:column> </apex:pageBlockTable> <apex:pageBlockSection id="pbs2" > <!-- Just to check what values are assigned to the parameter variables !--> Id: {!$CurrentPage.Parameters.SelectedAccountId} <br></br> Name: {!$CurrentPage.Parameters.SelectedAccountName} </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> Controller Class: public class AccountTask { Public List<Account> Acclist {set;get;} Public string AccId {set;get;} Public AccountTask () { Acclist = [select name,phone,type,Create_Task__c,SLAExpirationDate__c from Account where SLAExpirationDate__c != NULL]; } Public void CreateTask () { AccId = System.CurrentPageReference().getParameters().get('SelectedAccountId'); Task t = new Task (); t.WhatId = AccId; t.Subject = 'New VF Task'; t.Description = 'Gibberish'; insert t; } }
You need to pass your parameters with the <apex:commandbutton>.
Something like this:
Note: Do not delete the rerender attribute from <apex:commandbutton> otherwise it won't pass the param values as expected. It is kind of a bug. In case you have any thing to rerender, create <apex:outputPanel id="hidden" rendered="false"> and pass 'hidden' to rerender attribute.
Let me know if it helps.
Thanks.