2

I have a visualforce page with an apex:component in it. (This component is for headers, used in various other places). The component has an outputLink with actionSupport. OnClick of this Link, I have some updates done.

And I want to refresh the whole page. (Not just a section in the component). The below code DOES work. But when I click first time on the Link, the update happens, but no page refresh. When I click again (the button), the update happens, and my page also refreshes! The problem is: it isn't refreshing when I click for the first time!! What am I doing wrong.

Note: There are 2 controllers involved in this.

My VF Page

<apex:page title="" controller="ppController">
<apex:form>
      <c: HeaderV2 />
</apex:form>
</apex:page>

Here's my component.

<apex:component id="header1" controller="TemplateController" allowDML="true">
     <apex:form>
           <apex:outputLink><em>Set as Default</em>
               <apex:actionSupport event="onclick" action="{!UpdateToIntern}" rerender="header1" />
           </apex:outputLink>
     </apex:form>
</apex:component> 

Here's my controller method

public PageReference UpdateToIntern(){
        if(cList!= null && cList.size()>0){
            cList[0].Program__c = 'Intern';
            update cList[0];
        }   
        return null;    
    }

Update: I cannot use CommandButton etc because for those I need to use apex:form in the component which is causing error!

  • What happens if you take out rerender ? – Dominic Dec 18 '14 at 11:01
  • without reRender, no update also. I tried reRender="none". no difference – sfdcFanBoy Dec 19 '14 at 7:22
  • updateToIntern() exists in which controller - TemplateController or ppController ? – cropredy Dec 20 '15 at 23:47
  • give an id to <apex:page> and refer that in reRender. That will reRender the entire page – Ysr Shk Jun 28 '18 at 5:58
0

You're not returning any page reference in the apex class. To refresh the page after the action, you can use oncomplete attribute of apex:actionSupport.

<apex:actionSupport event="onclick" action="{!UpdateToIntern}" rerender="header1" oncomplete = "location.reload();"/>

You can also update your class as below

public void UpdateToIntern(){
        if(cList!= null && cList.size()>0){
            cList[0].Program__c = 'Intern';
            update cList[0];
        }   
    }
  • That didn't work either. No refresh. – sfdcFanBoy Dec 18 '14 at 10:01
  • Just to bring to your notice, even with earlier code. When I click first time on the Link, the update happens, but no page refresh. When I click again, the update happens again, and my page refreshes! But it isn't refreshing when I click for the first time! – sfdcFanBoy Dec 18 '14 at 10:23
0

Have you thought about using jQuery? I've successfully used it in a couple of VF pages successfully and it might work. I haven't used it in a double component configuration like this, but it might work.

<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />
<script>
$j = jQuery.noConflict();
j$(document).ready(function() 
{
    $j('#btnName').click(function() 
    {
        window.opener.location.reload();
    });
});
</script>

The other recommendation is a good one; however, I think since you're using a double component, you may need to reference the parent window, try this:

<apex:actionSupport event="onclick" action="{!UpdateToIntern}" rerender="header1" oncomplete = "window.opener.location.reload();"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.