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
M477M477 

Refresh VisualForce PageBlock

The following is a simplified version of a table that sits in the page layout of the Case standard object.

 

<apex:page standardController="Case" extensions="aResourcesListController">
<apex:form >
    <apex:pageBlock id="table1">
        <apex:pageBlockTable value="{!aResourcesList}" var="aResource" >
            <apex:column >
                <apex:facet name="header">Column 1</apex:facet>
                <apex:inputField value="{!aResource.field__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Column 1</apex:facet>
                <apex:outputText value="{!aResource.field__r.someOtherField}"/>
            </apex:column>
        </apex:pageBlockTable>
        <br/> 
        <apex:commandButton action="{!updateTable}" value="Save" rerender="table1"/>
        <apex:commandButton action="{!insertRow}" value="New" rerender="table1"/>
    </apex:pageBlock>
</apex:form>
</apex:page>

 This should update the table when the Save commandButton is clicked. It does update the database but to get the visualforce page to update the user must manually refresh the whole page. How can I get the VisualForce PageBlock to refresh when the user clicks save? Is this possible to do without refreshing the entire page?

 

Thanks,

Matt

 

bob_buzzardbob_buzzard

There's nothing in the docs to say that a pageblock can't be rerendered, so I'd expect your save to work, assuming you aren't trying to redirect to a different page from your action method.

 

Usually when I see this behaviour it means that an error has been encountered, but the rerender stops it being displayed.

 

A couple of things to try, highlighted below:

 

 

 

<apex:page standardController="Case" extensions="aResourcesListController">
<apex:form >
    <apex:pageMessages id="messages"/>
    <apex:actionStatus id="actStat" startText="Calling ajax" stopText="Ajax call complete"/>
    <apex:pageBlock id="table1">
        <apex:pageBlockTable value="{!aResourcesList}" var="aResource" >
            <apex:column >
                <apex:facet name="header">Column 1</apex:facet>
                <apex:inputField value="{!aResource.field__c}"/>
            </apex:column>
            <apex:column >
                <apex:facet name="header">Column 1</apex:facet>
                <apex:outputText value="{!aResource.field__r.someOtherField}"/>
            </apex:column>
        </apex:pageBlockTable>
        <br/> 
        <apex:commandButton action="{!updateTable}" value="Save" rerender="table1, messages" status="actStat"/>
        <apex:commandButton action="{!insertRow}" value="New" rerender="table1"/>
    </apex:pageBlock>
</apex:form>
</apex:page>

 The first will display any error messages that may have occurred, while the second will allow you to see that  the request starts and finishes correctly.

 

If all looks good at that point, try wrapping your pageblock in an outputPanel and rerendering that.

 

Devendra NataniDevendra Natani

You can also create a getter method of  "aResourcesList". For e.g.

 

 

public List<case> getaResourcesList()
{
// add your logic and  
// return List<Case>
}

Please let me know if there is any issue.

 

 

Thanks,

Devendra

Blog

M477M477

Thanks Bob,

 

This did display the start then stop text and the objuct was still updated but the other fields:

!aResource.field__r.someOtherField

remain blank untill the page is refreshed. I also tried:

 

 

PageReference curPage = ApexPages.currentPage();
curPage.setRedirect(true);
return curPage;

 at the end of the updateTable function (and changed the type from void to PageReference) but that just returns a blank page segment. I replaced the above example with:

 

 

 

PageReference curPage = new PageReference('http://google.com');
return curPage;

 and that code did work, returning the google home page in a page segment.

 

Is there a way I can just refresh the entire page after the updateTable function is called?

 

bob_buzzardbob_buzzard
Ah - are you looking to specify a lookup field and then pull back some fields rom the related object? If so, you'll need to retrieve those additional field yourself, or you may be able to us the reset and addfields methods on the standard controller to populate them. All that specifying the lookup will do is populate a single I'd field.
M477M477

Ok that makes sense, I have a lookup field and pull down a bunch of fields from the looked up record. As there are other page elements that use data recorded in this table, it looks like the easiest corse of action would be a full page refresh once the user saves the table. Sorry if this sounds like a ridiculously straightfoward question but is there a way of refreshing the entire page once the update function is called? (not just the page element)

bob_buzzardbob_buzzard
Yes - just remove the rerender attribute. You ma find that after you've updated the record in the database, it's better to carry out a client side redirect (set h redirect property on th page reference to true) as this will cause your controller to be constructed anew.
Pratibh PrakashPratibh Prakash

Hello,

 

Please provided the contoller code as well.