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
KeithJKeithJ 

Command Link Without page redirect

Hi there. I have a commandLink which wraps around an apex param.

I have set the value and action attributes for the commandLink although a page redirect occurs.

I do not want this to happen.

The associated action method in my controller has a return type of PageReference but returns null, although

when I click the link a page redirect still occurs.

Is there a way to bypass the page redirect with a commandLink?

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
mtbclimbermtbclimber
Sorry if I am missing something obvious but without rerender (or oncomplete) commandLink will always do a full page refresh.  So if you don't want the full page refresh AND you don't need/want to refresh any part of the page then provide a rerender to an empty or bogus target though I don't really understand the strategy behind just setting a value in the controller and not doing anything with that information.
Message Edited by mtbclimber on 05-13-2009 09:36 PM

All Answers

mtbclimbermtbclimber

Can you post your code please (page & controller/method)? (or a small reproducible case)

KeithJKeithJ

Certainly:

 

Here's my visualforce:

 

 

<apex:commandLink value="{!timeSlotVar.timeSlotStatus}" action="{!printId}" immediate="true"> <apex:param value="{!timeSlotVar.timeSlotId}" name="{!timeSlotVar.timeSlotId}" assignTo="{!testId}" /> </apex:commandLink>

 

And here's the relevant sections of my controller:

 

 

public Id testId { get; set; } . . . public PageReference printId() { System.debug('***** TESTID IS: ' + testId); return null; }

 Thanks

 

 

 

 

KeithJKeithJ

Forgot to mention that the command link is encapsulated by an apex repeat

of which the var is timeSlotVar

 

Thanks

mtbclimbermtbclimber
thanks. are you redirected to another page or are you wondering why the full page is refreshed?
KeithJKeithJ

The full page is refreshed which I don't want...

Is there a way to cancel the refresh with a bit of Javascript incorporated into the onclick or oncomplete attributes?


Basically what I am trying to do, is simply set a property in my controller (which I do) and then do a rerender on a pageBlock - all without a complete page refresh...

It takes away from the elegance of rerenders.

Thanks

mtbclimbermtbclimber

Well, you haven't specified a rerender attribute on the commandlink which is the queue to do partial page, otherwise it's full page.

 

Also, I don't think your param is going to be set with immediate="true" on your link. I suspect you'll need to drop that.

KeithJKeithJ

Thanks for the reply. I haven't gotten to the rerender yet because if the page does a full refresh, I won't need it.

Yep, the immediate=true is superfluous...

Any other ideas welcomed!

mtbclimbermtbclimber
Sorry if I am missing something obvious but without rerender (or oncomplete) commandLink will always do a full page refresh.  So if you don't want the full page refresh AND you don't need/want to refresh any part of the page then provide a rerender to an empty or bogus target though I don't really understand the strategy behind just setting a value in the controller and not doing anything with that information.
Message Edited by mtbclimber on 05-13-2009 09:36 PM
This was selected as the best answer
KeithJKeithJ

Perfect!

That worked a treat ;)