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
SennahSennah 

Trouble with reloading a page with VisualForce element

Hi community,

 

I am working on a VisualForce element which is included in the page layout of my custom object "invoice".

The VF page gets two different lists of opportunities from the account where both, invoice and opptis are  connected to. From those lists you can select opptis and process them.

The basic function works just fine so far.

 

Now, here's my problem: Once the processing is complete I want to fully reload the invoice - the whole page, including the related lists and so on.

 

I tried setting PageReference for my action method and several javascript actions for onComplete.

The PageReference loads the invoice again in the iframe where my VF element was.

The javascripts don't load the whole page again. If I were able to get the current invoice ID this might work:

 

 

<apex:commandButton value="Add Selected" action="{!processSelectedAdd}" onComplete="parent.location.href = '/'"/>

 

 ... by adding the ID to the parent.location.href value.

 

Here's the part of my controller with the PageReference I tried. You see "return null;" is not active at the moment. I tried that too but it doesn't worked out. To get the javascript redirect working at all the return value for this must be null:

 

public PageReference processSelectedAdd() { List<Opportunity> selectedOpportunities = new List<Opportunity>(); for (oOpportunity oOpp : getOpportunities()) { if (oOpp.selected == true) { selectedOpportunities.add(oOpp.opp); } } //System.debug('processing the following:'); for (Opportunity opp : selectedOpportunities) { opp.Invoice__c = this.invoice.Id; update opp; } PageReference pageRef = new PageReference('/' + this.invoice.Id); pageRef.setRedirect(false); return pageRef; //return null; }

 

 And here's the whole VF object:

 

 

<apex:page standardController="CM_Invoice__c" extensions="OpptiListControllerWrapper" tabStyle="Opportunity"> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Add Selected" action="{!processSelectedAdd}" onComplete="parent.location.href = '/'"/> </apex:pageBlockButtons> <!-- --> <apex:pageBlockTable value="{!opportunities}" var="o" id="table"> <apex:column > <!-- --> <apex:inputCheckbox value="{!o.selected}"/> </apex:column> <!-- --> <apex:column value="{!o.opp.Name}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:form> <apex:form > <apex:pageBlock > <apex:pageBlockButtons > <apex:commandButton value="Remove Selected" action="{!processSelectedDel}" /> </apex:pageBlockButtons> <!-- --> <apex:pageBlockTable value="{!opportunities2}" var="o" id="table2"> <apex:column > <!-- --> <apex:inputCheckbox value="{!o.selected}"/> </apex:column> <!-- --> <apex:column value="{!o.opp.Name}" /> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>

 

 

 

 

 Really thankful for any hints!

 

Best,

Hannes

 

bob_buzzardbob_buzzard

You can use the Javascript reload function to "refresh" the current page:

 

e.g. window.location.reload()

ThomasTTThomasTT

I guess I had a different problem with the same cause. 

 

Now (not 2 releases ago), VF pages are running on https://c.cs2.visual.force.com domain, and main pages are on https://cs2.salesforce.com. IE forbids any action which accesses to contents in different domain, because it is treated as "Cross Site Scripting" (Firefox somehow allows it, but security-wise, IE is right).

 

I think you're trying to control main page from VF page by using "parent.location.href" and you're getting error from IE.

2 relaeses ago, it was ok because they were running on the same domain, but not anymore.

I guess the reason they divided resources is to avoid the Cross Site Scripting, so there shouldn't be a workaround in this case.

 

I don't know people or SFDC has found a solution for it. If anyone knows about it, please post the information.

 

ThomasTT

 

[Edit]

 

Reload is a nice idea!  Let me know if it worked or not!

Message Edited by ThomasTT on 09-16-2009 05:17 PM
SennahSennah

Hi guys,

 

thanks to you both for answering.

 

Unfortunately the reload function does not work as for the reason that  Thomas explained.

 

I am sorry, I should have made it more clear that I already tried several combinations of reload with location, parent, top, window and so on. They are all not giving the wanted result. It is possible to just reload the iframe where the VF element is but not the whole site.

 

Maybe Salesforce can help on this?

 

Best,

Hannes

ThomasTTThomasTT

Wow... I imagined that window object is shared with the iFrame object... becase it's on the window... but it seems that iFrame still can't control anything about parent via window (it can access to window object, but can't access to function related to other contents... smart)

 

If SFDC moved VF pages for security reason, there shuouldn't be a solution... because solutions means security breaches.

 

I wish SFDC provides some bypass function like apex:component.

 

ThomasTT

JMPlayer22JMPlayer22

I was having a similar issue and saw this thread.  I actually got mine to do a "reload" of the entire page and not just the visualforce section I have on my page layout for cases. I added: 

 

 

parent.location.href="/{!Case.Id}"

 just to get it to redirect to the same Case page.  Seems to be working fine.

 

DevNVDevNV

Hi there,

I also struggled with this and found I could refresh the top level page using a CommandLink tag in the VF page that called a controller method.  The controller method returns a Page Reference and I add a target="_top" to the commandLink tag.

 

Controller method:

public PageReference del() {
        try {
            if (lineId != null ) {
                MyCustomObject__c rec = new MyCustomObject__c(id = lineId);
                DELETE rec;
                
            }
        } catch (Exception e) {
            ApexPages.addMessages(e);
            system.debug('error deleting: '+e);
            return null;
        }
        PageReference nextPage = new PageReference('/'+parentid);
        nextPage.setredirect(true);
        return nextPage;
}

 

And my VF page piece:

<apex:dataTable value="{!lines}" var="item"   >
            <apex:column headerValue="Action" 
                <apex:outputLink value="/{!item.id}/e?&retURL=/{!MyCustomObject__c.id}" target="_top">Edit</apex:outputlink>
                |&nbsp; <apex:commandLink action="{!del}" value="Del" onclick="return window.confirm('Are you sure?'); " target="_top">
                    <apex:param assignto="{!lineid}" name="lineid" value="{!item.id}"/>
                </apex:commandLink>
                |&nbsp; <apex:outputLink value="/{!item.id}" target="_top">View</apex:outputlink>
            </apex:column>

            ... other apex:columns

</apex:dataTable>

 I dropped the VF page inside my parent record page layout and it seemed to work.  The only funny thing with the Delete link is that it added ?inline=1 to the URL, which turned on the VF Page editor bar inside the VF Page component if my user had the "Development Mode" set. 

 

Hope that helps.

 

Niki

www.vankerksolutions.com

bob17bob17

DevNV,

 

You just saved me a boatload of grief.  My custom VF control was updating updating a field on the detail record and if the user did an in-line edit and hit Save, the value was being reset.  Now that I can have the VF control refresh the entire page I don't have that risk.  Own you one!

 

Thanks