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
EmsEms 

CommandLink param works first click, but never again!

The basic goal is to select a category on the left hand side of the page, and reload the entire page with content based on that category.  For some weird reason this works the first time the user selects a category, but never again! Page loads with category "all" selected, first selection of category reloads page with data just for that category, and all succesive selects reload the page with whatever the last selection was!!!

 

Visualforce:

 

<apex:datatable value="{!Categories}" var="cat" styleClass="catalog_menu"> <apex:column headerValue="Categories"> <apex:commandLink action="{!selectCategory}" value="{!cat}"> <apex:param name="ctgry" value="{!cat}"/> </apex:commandLink> </apex:column> </apex:datatable>

 

Controller:

 

public PageReference selectCategory() { setCtgry(); setItems(); //executes the SOQL that selects the content to show on the page PageReference pageref = ApexPages.currentPage(); pageref.setRedirect(true); return pageref; } public void setCtgry() { String cat = ApexPages.currentPage().getParameters().get('ctgry'); if(cat == null) cat = 'All'; currCategory = cat; } public void setItems(){ if (currCategory != null && currCategory != 'All') Items = [Select o.Id from Opportunity o where o.Auction_Category__c = :currCategory order by o.Item_Number__c]; else Items = [Select o.Id from Opportunity o order by o.Item_Number__c]; }

 

 

 

 My best guess is I'm not understanding how the SelectCategory PageReference returned is being handled - I THINK that the page reference returned by SelectCategory is used to reload the page.... but given that I am setting parameters for the page, whydo they never show up in the address bar of the browser?

 

Any help greatly appreciated!

 

 

bob_buzzardbob_buzzard

When you set a parameter in this way, it will be added to the URL when the page is submitted back to execute the command link.  I think that the reason you aren't seeing this in the address bar is that you are returning a PageReference with the redirect attribute set to true - this forces a client redirect to the page reference, dropping any information in the URL.

 

You can add parameters to the PageReference using getParameters().put(key, value).