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
MukulMukul 

Cant pass param from VF to Controller

Hi all,

 

I have this issue where i am unable to pass the param from the VF to Controller. It shows Null when i try to print it out.

 

Here is my VF Code:

 

<table width="100%"> <th> Rule Name </th> <th> Action </th> <apex:repeat value="{!ruleNameList}" var="ruleNameList"> <tr> <apex:repeat value="{!ruleNameList}" var="ruleNameLsit1"> <td><apex:outputText value="{!ruleNameList}"/></td> <td> <apex:repeat value="{!ruleNameList}" var="ruleNameLsit1"> <apex:commandLink value="Edit / " action="{!editRule}"/> <apex:commandLink action="{!deleteRule}" onClick="confirmCancel();" value="Delete" id="theCommandLink3"> <apex:param value="{!ruleNameList}" id="param" assignTo="{!param}"/> </apex:commandLink> </apex:repeat> </td> </apex:repeat> </tr> </apex:repeat> </table>

 

 Here is my Controller Code:

 

public String param {get; set;} // Delete Rules public PageReference deleteRule(){ String id = getRuleSetId(); System.debug('RULENAME: ' + param + ', RULEID: ' + id); // delete all rules associated with it List <ScoringRule__c> scoringrules = [Select Id From ScoringRule__c Where RuleName__c =: param and RuleSetId__c =: id ]; delete scoringrules; return null; } public List<String> getRuleNameList() { String ruleId = getRuleSetId(); // System.debug('In getRuleNameLsit'); List<ScoringRule__c> rulenames = [select ruleName__c, Id from scoringRule__c where ruleSetId__c =: ruleId]; // Save it in a Map so that we can eliminate duplicates Map<String, String> ruleNamesMap = new Map<String, String>(); for(ScoringRule__c s : rulenames) { ruleNamesMap.put(s.ruleName__c, s.Id); } List <String> ruleNamesList = new List<String>(); // Return it in a form which will be compatible with it Set <String> s = ruleNamesMap.keyset(); for (String si : s) { ruleNamesList.add(si); } return ruleNamesList; }

 

Any help is appreciated!!

 

Thanks in advance

Muku

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Muku,

 

There's a few small changes you need to make:

 

1) You can't use apex: param the way that you tried. It just won't work the way you expect. Param is an "input" device used to pass a value into a component.

 

2) While you can legally use a "var" with the same name as the list method, I don't recommend it. It's downright confusing and might be the cause of some of your problems.

 

3) Since apex: param isn't working the way you'd expect, it's no surprise then that deleteRule won't work the way you expect either.

 

All in all, I'd recommend the following changes:

 

1) Create a small wrapper class (you can include it inside the controller's class, I won't tell) that looks like this:

 

public class RuleEntry {

    public String Id { get; set; }

    public String Name { get; set; }

    public void EditRule() { /* invoke the rule editor */ }

    public void deleteRule() { if(Id<>null) { delete new ScoringRule__c(Id=Id); } }

}

 

2) Change your controller to use List<RuleEntry> (the new class) instead of List<String>.

 

3) Change your visualforce page to something like the following:

 

<apex:dataTable value="{!ruleNameList}" var="ruleEntry" columns="2" id="ruleListTable">

  <apex:column>

    <apex: outputText value="{!ruleEntry.Name}" />

  </apex:column>

  <apex:column>

    <apex:commandLink value=" Edit " action="{!ruleEntry.EditRule}" reRender="ruleListTable" />

    <apex:commandLink value= " Del " action="{!ruleEntry.deleteRule}" reRender="ruleListTable"

       onClick="return confirmCancel();" />

  <apex:column>

</apex:dataTable>

 

4) You'll have to change your getRuleNameList() function as well to support this new wrapper class. I've given you most of what you need at this point, so this part shouldn't be so bad.

All Answers

sfdcfoxsfdcfox

Muku,

 

There's a few small changes you need to make:

 

1) You can't use apex: param the way that you tried. It just won't work the way you expect. Param is an "input" device used to pass a value into a component.

 

2) While you can legally use a "var" with the same name as the list method, I don't recommend it. It's downright confusing and might be the cause of some of your problems.

 

3) Since apex: param isn't working the way you'd expect, it's no surprise then that deleteRule won't work the way you expect either.

 

All in all, I'd recommend the following changes:

 

1) Create a small wrapper class (you can include it inside the controller's class, I won't tell) that looks like this:

 

public class RuleEntry {

    public String Id { get; set; }

    public String Name { get; set; }

    public void EditRule() { /* invoke the rule editor */ }

    public void deleteRule() { if(Id<>null) { delete new ScoringRule__c(Id=Id); } }

}

 

2) Change your controller to use List<RuleEntry> (the new class) instead of List<String>.

 

3) Change your visualforce page to something like the following:

 

<apex:dataTable value="{!ruleNameList}" var="ruleEntry" columns="2" id="ruleListTable">

  <apex:column>

    <apex: outputText value="{!ruleEntry.Name}" />

  </apex:column>

  <apex:column>

    <apex:commandLink value=" Edit " action="{!ruleEntry.EditRule}" reRender="ruleListTable" />

    <apex:commandLink value= " Del " action="{!ruleEntry.deleteRule}" reRender="ruleListTable"

       onClick="return confirmCancel();" />

  <apex:column>

</apex:dataTable>

 

4) You'll have to change your getRuleNameList() function as well to support this new wrapper class. I've given you most of what you need at this point, so this part shouldn't be so bad.

This was selected as the best answer
MukulMukul

Thanks for the reply SFDCFox.

 

I followed your steps.

 

However, my getRuleNameList is still complaining though. Here is the snippet:

 

public List<RuleEntry> getRuleNameList() {
String ruleId = getRuleSetId();
// System.debug('In getRuleNameLsit');
List<ScoringRule__c> rulenames = [select ruleName__c, Id from scoringRule__c where ruleSetId__c =: ruleId];
// Save it in a Map so that we can eliminate duplicates
Map<String, String> ruleNamesMap = new Map<String, String>();
for(ScoringRule__c s : rulenames) {
ruleNamesMap.put(s.ruleName__c, s.Id);
}
List <RuleEntry> ruleNamesList = new List<RuleEntry>();
// Return it in a form which will be compatible with it
Set <String> s = ruleNamesMap.keyset();
for (string si : s) {
ruleNamesList.add(si);
}
return ruleNamesList;
}

 

It says that i cant add a String to the RuleEntry List. It complains on this lane:

	ruleNamesList.add(si);

 

 

 Can anyone tell me whats wrong?

 

Thanks again!

Regards

Mukul

 

MukulMukul

Hi there,

 

I wasnt passing the right constructor method in my wrapper class. I fixed that and it worked! 

 

Thanks for youe help!

 

Regards

Mukul