+ Start a Discussion
Ken KoellnerKen Koellner 

ActionFunction takes user to PageReference

I want to call an action method in a VF controller and have it return a PageReference that the user goes to (it's actually null, I'm going back to the same page) just like an apex:commandLink.  But, I need to do it onChange of a selectOption.  I'm using an actionFunction that does a rerender but it doesn't function the same as a page reload because of complex script and styles on the page.

So what I really want to do is the equivent of using apex:commandLink to call an actionMethod and go to the Page Reference returned but trigger it from onChange of a selectOption?

Anyone know how to do that?  Basically load a new page based on a PageReference from an onChange rather than a rerender?
 

W

Ajay Nagar 7Ajay Nagar 7
Use action support for onchange like this:

<apex:selectList value="{!selectedvalue}" multiselect="false" size="1" >
    <apex:actionSupport event="onchange" action="{!actiononchange}" rerender="redirect_method_name"/>
    <apex:selectOptions value="{!optionProductList}" />
</apex:selectList>

Use below code to reload page in VF controller method called via action support .

PageReference pageRef = new PageReference(ApexPages.currentPage().getUrl());
pageRef.setRedirect(true);
return pageRef;

Or call a javascript method oncomplete of action Support with below code :
window.location.href = window.location.href;
Ken KoellnerKen Koellner
Where is redirect_method_name defined?  That has to be the id of something on the page.  Is that some element automatically included by SF? And doesn't that yield only a partial rerender?  Can you explain how that works?

On the PageReference, I don't believe I would want redirect.  I believe redirect will reload the controller and I want the controller already in memory.  But perhaps that could just be removed.

I thought about just resetting the location to the same location as in your last explain.  I don't know if that will work but I might try it sometime.
Ajay Nagar 7Ajay Nagar 7
Hi Ken,

Remove 'redirect_method_name' as it is not related to your code,it is used to load again any visualforce component by using its ID after action support completes.
Above examples of page reload will execute your controller again.What you can do is rerender the whole page by replacing 'redirect_method_name' with ID of any Visualforce component that contains all the page like Outpanel ID etc.

Thanks
Ajay
Ken KoellnerKen Koellner
Ajay, what you describe in your recent post is specifically what I am trying to avoid.  I do not want to use rerender.  Reason being, we do not get the exact same behavior as using commandLink even when we select rerender="Id of the entire page".  We're not sure why it behaves differently but it does.  The whole reason for my post is specifically to avoid the rerender option and use a PageReference returned by an action methods but trigger it from onChange of a dropdown.

Maybe something with onComplete that will load the next revision of the page would be more like what we are trying to do.