+ Start a Discussion
Srinu@dreamsSrinu@dreams 

How to refresh a vf page?

I want to refresh the current page after inserting values, those values should not visible after refreshing.

HariDineshHariDinesh

Can you elaborate what you are looking for…?

balaji malemarpurambalaji malemarpuram

Hi,

If you want to remove the values from controllers(like textbox,picklist etc) on page then just re create instance for that object in save method after insert statement.It is helpful to you.

SamReadySamReady

Are you trying to refresh a custom VF page after button click?

 

If so, the method you call with the insert function should be of type PageReference and return null; This way it will refresh the current page after performing the DML operation.

 

If you have certain fields on your page that should no longer be visible after the insert, surround that section of the page (within the form) with an <apex:outputPanel> and give this tag an attribute of rendered="{!someVariable}". In your constructor set that boolean variable to true, and in your method set the boolean to false so that after the page refreshes the panel will not render. 

 

Here is a small example

 

public boolean someVariable {get;set;}

 

public yourConstructor(){

    someVariable = true;

}

 

public PageReference mySave(){

    insert myValues;

    someVariable = false;

    return null;

}

 

 

...........

 

<apex:pageBlock>

<apex:form>

    <apex:pageBlockButtons>

         <apex:commandButton action="{!mySave}" value="Save"/>

     </apex:pageBlockButtons>

 

     <apex:outputPanel rendered="{!someVariable}">

         <apex:pageBlockSection>

               <!-- anything in here won't show up after save -->

          </apex:pageBlockSection>

      </apex:outputPanel>

 

      <!-- anything out here will show up after save -->

</apex:form>

</apex:pageBlock>

 

You can add another output panel outside of your first output panel to only show up after you do your insert as well, but the boolean defining that rendered attribute would be the opposite of how I showed you above...

 

Does this answer your question?

Vishal GuptaVishal Gupta

Hi,

Do one thing when you hit save button then set a boolean variable to true/false in the method that is called on hitting save button. After that whatever part u want not to be visible,wrap that part in an OutputPanel with rendered attribute ={!that variable}.

This will help you to render that panel as per ur need.