+ Start a Discussion
Sanju118Sanju118 

Refresh Visualforce Page

Hi All,
           I have created a Apex Detail page for Event. I have button on this Detail page which opens a Second Apex Page, Once I Click the Button on this new Popped Visual force Page, I need the Pop-Up window to be closed and the Parent Visual force window to be refreshed.

Please let me know, if any of us here has a solution for this.

Thanks All,
Sanjay
Best Answer chosen by Admin (Salesforce Developers) 
NaishadhNaishadh

Hi,

 

I don't know you have found the solution for your problem or not but I was just searching for something else and found this. Following is the code for window refresh. 

 

I have made changes in your code only.

 

public PageReference create() 
{
String op = ApexPages.currentPage().getParameters().get('id');
integer i;
integer j = FA.size();
FA_Branch__c so;
for (i=0;i<j;i++)
{
so = new FA_Branch__c();

so.Branch__c = op;
so.FA_PB_Name__c = FA[i];
insert so;
}
PageReference curPage = ApexPages.currentPage();
curPage.getParameters().put('success','true');
curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
curPage.setRedirect(true);
return curPage;
//return null;

}
In your apex page 
<apex:page controller="checkbox" showHeader="false" sidebar="false">
<script>
if("{!$Request.success}" == "true") {
parent.window.close();
parent.window.opener.location.href = "/{!$Request.id}";
}
</script>
</apex:page>
Message Edited by Naishadh on 02-20-2009 04:12 AM

All Answers

jonathanrico.jonathanrico.
Hello, this script does it:

    <script>
        parent.window.opener.location.reload();
        parent.window.close();
    </script>

however, I tried to put this in the onclick event of the button and got some errors while using it in IE.. and after opening a few times the popup window I wasn't able to load any SF page.. My solution to this issue was the following:


Created a VF page only for closing purposes:

Code:
<apex:page showHeader="false">
    
    <script>

  parent.window.opener.location.reload();
  parent.window.close();
    </script>
    
    <apex:pageBlock >
    <apex:pageMessage strength="3" severity="info" title="Done" detail="Your request has been processed."/>

    </apex:pageBlock>
    
</apex:page>

 And then assigned the following action to my button:

Code:
<apex:pageBlockButtons >
<apex:commandButton value="Close" action="{!gotoclosePage}" rerender="refreshpanel" immediate="true"/>
</apex:pageBlockButtons>

My Controller has the following function:

 public PageReference gotoclosePage(){
  
  PageReference ref = Page.closePage;
  ref.setRedirect(true);
  return ref;
 }

 
Hope this helps you.



Sanju118Sanju118
Thanks Jonathan,
                               I tried your approach, but this immediately closes the pop up page and refreshes the Parent Window,
However Users have to do some work on the pop up window and then once they press the Button , this action should take place...

Please let me know, if anyone around also can also help me on this..

Page Code -
Code:
<apex:page controller="checkbox" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock title="FA/PB List">

<apex:pageBlockButtons location="top"> <apex:commandButton value="Add" action="{!create}" rerender="detail" status="status"/> </apex:pageBlockButtons>
<apex:selectCheckboxes value="{!FA}" layout="pageDirection"> <apex:selectOptions value="{!value_1}" /> </apex:selectCheckboxes>
</apex:pageBlock> </apex:form>
<apex:outputPanel id="detail"> <apex:actionstatus id="status" startText="Adding..."> <apex:facet name="stop"> <apex:outputPanel > <apex:dataTable value="{!FA}" var="c">
</apex:dataTable> </apex:outputPanel> </apex:facet> </apex:actionstatus> </apex:outputPanel> </apex:page>

 Controller  -
Code:
public class checkbox 
    {
    public PageReference create() 
        {
        String op = ApexPages.currentPage().getParameters().get('id');
        integer i;
        integer j = FA.size();
        for (i=0;i<j;i++)
            {
            FA_Branch__c  so = new FA_Branch__c();
          
            so.Branch__c = op;
            so.FA_PB_Name__c = FA[i];
            insert so;
            }
            return null;
 
        }

   
    FA_PB__c[] FAPB = [Select id,FA_PB_Name__c  from  FA_PB__c limit 10];
    List<FA_PB__c> lis = new List<FA_PB__c>(FAPB);
    String[] FA = new String[]{};
 
    public List<SelectOption> getValue_1() 
        {
        List<SelectOption> options1 = new List<SelectOption>();
        options1.clear();
        for(FA_PB__c j:FAPB )
            {
            options1.add(new SelectOption(j.Id,j.FA_PB_Name__c));
            }
        return options1;
        }
        
        public String[] getFA() 
        {
        return FA;
        }
        public void setFA(String[] FA) 
        {
        this.FA = FA;
        }
        public void setValue_1()
        {
        }
   }

 


NaishadhNaishadh

Hi,

 

I don't know you have found the solution for your problem or not but I was just searching for something else and found this. Following is the code for window refresh. 

 

I have made changes in your code only.

 

public PageReference create() 
{
String op = ApexPages.currentPage().getParameters().get('id');
integer i;
integer j = FA.size();
FA_Branch__c so;
for (i=0;i<j;i++)
{
so = new FA_Branch__c();

so.Branch__c = op;
so.FA_PB_Name__c = FA[i];
insert so;
}
PageReference curPage = ApexPages.currentPage();
curPage.getParameters().put('success','true');
curPage.getParameters().put('id',Apexpages.currentPage().getParameters().get('id'));
curPage.setRedirect(true);
return curPage;
//return null;

}
In your apex page 
<apex:page controller="checkbox" showHeader="false" sidebar="false">
<script>
if("{!$Request.success}" == "true") {
parent.window.close();
parent.window.opener.location.href = "/{!$Request.id}";
}
</script>
</apex:page>
Message Edited by Naishadh on 02-20-2009 04:12 AM
This was selected as the best answer