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
Nikhil SomvanshiNikhil Somvanshi 

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="{!}" id="name"/>
              <apex:column value="{!}"/>
              <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="{!}"/>
              <apex:column headerValue="Action">
              <apex:commandButton value="Create Task" action="{!CreateTask}"/>
          <apex:pageBlockSection id="pbs2" > <!-- Just to check what values are assigned to the parameter variables !-->
          Id: {!$CurrentPage.Parameters.SelectedAccountId} 
          Name: {!$CurrentPage.Parameters.SelectedAccountName}

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;

Narender Singh(Nads)Narender Singh(Nads)

You need to pass your parameters with the <apex:commandbutton>.

Something like this:
<apex:commandButton value="{!}" action="{!CreateTask}" reRender="pbs2">
           <apex:param name="SelectedAccountId" value="{!}" />
           <apex:param name="SelectedAccountName" value="{!}" />

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.