1

Can anyone tell me how to rerender a particular pageblock when the action method using pageReference?

My use case is I want to rerender a particular block when I click the command button

VFP:

<apex:commandButton action="{!Download}" value="download" id="chatterDownload" reRender="FeedFilePanel"/><br/>   
<apex:outputPanel id="FeedFilePanel" rendered={!feedFile}>    
    If you want to download the files that are attached to the Feeds then click below button<br/>  
    <center>
        <apex:commandButton id="uploadZipButton" value="Download Files" action="{!uploadZip}" />
    </center>
</apex:outputPanel>

Apex class:

public PageReference Download(){  
       feedFile=true;

        if(!feedItemList.isEmpty()){
            String fileName = 'Feeds' +  DateTime.Now() + '.pdf';
            Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename=' + fileName);
            PageReference chatterdownload= Page.ChatterDownload;
            chatterdownload.setRedirect(false);
            return chatterdownload; 
        } 
        else{
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Feeds, Please select an another Date to Download'));
            return null;
        }     
   }

Please someone tell me how to use rerender attribute in that command button?

12
  • Try rerendring the whole form <apex:commandButton action="{!Download}" value="download" id="chatterDownload" reRender="YourFormId"/><br/> Apr 21, 2015 at 10:14
  • @ShankerPaudel : it doesnt work if i rerender whole form Apr 21, 2015 at 10:40
  • Do you have apex:pagemessage inside your page. It might be that you are geting an error. Please validate debug logs Apr 21, 2015 at 13:20
  • @ShankerPaudel : Yeah I have already added apex:pagemessages tag Apr 21, 2015 at 13:24
  • Please add its id in rerender arrtibute yourpagemessageid , yourFormId if pagemessage is not inside your form. Apr 21, 2015 at 13:42

3 Answers 3

0

Create an outputPanel which is parent to both commandbutton and your current output pannel and put the parent panel id in reRender in command button.

Your code will look something like this

<apex:outputPanel id="parentPanelId">
<apex:commandButton action="{!Download}" value="download" id="chatterDownload" reRender="parentPanelId"/><br/>   
<apex:outputPanel id="FeedFilePanel" rendered={!feedFile}>    
    If you want to download the files that are attached to the Feeds then click below button<br/>  
    <center>
        <apex:commandButton id="uploadZipButton" value="Download Files" action="{!uploadZip}" />
    </center>
</apex:outputPanel>
</apex:outputPanel>
2
  • but the first command button is usng pageReference class Apr 21, 2015 at 10:31
  • I have tried your idea but it doesn't work Apr 21, 2015 at 10:39
0

Please try to replicate this code and ask if you have any trouble. Please add this code to your org for test. Thanks

Class

public class SanxboxPageReferenceCtrl {

    public PageReference testIt() {
        abc = '1234Updated';
        return null;
    }


    public string abc {get; set;}

    public SanxboxPageReferenceCtrl(){
        abc = '1234';
    }
}

Visualforce

<apex:page controller="SanxboxPageReferenceCtrl">

    <apex:form id="frmMain">
        {!abc} <br></br>
        <apex:commandButton value="Test" reRender="frmMain" action="{!testIt}"/>
    </apex:form>

</apex:page>
9
  • It works fine but If you use page Reference then it will not work. like add the below snippet to your testIT method. PageReference newRedirect=new PageRefernce('/apex/YourPreviousPage'); newRedirect.setRedirect(false); return newRedirect; Apr 24, 2015 at 7:03
  • If you use rerender you are making an ajax call you cannot redirect like this. You need to use on complete attribute and redirect on it with javascript.window.location.replace("/apex/abcpage); Apr 24, 2015 at 9:08
  • But I need to do some operations after that I wanna to download second pages as html. Apr 24, 2015 at 9:17
  • For that do not rerender the page. Do opreations redirect to other page. Apr 24, 2015 at 9:55
  • Am using same controller for both first and second page. Apr 24, 2015 at 10:27
0

This is because of you are using page-reference and it start apex reading code from beginning and feedfile got back null try

render="{! If(feedFile=='true' ,true,false) }"/>

and instead of return pg use

return null

and command button to rerender form

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.