+ Start a Discussion
Hugo StoupeHugo Stoupe 

Rerender on Command Button is driving me crazy ;)

I have looked at the forums and for some reason, I think my code is complete, however, my page is not re-rendering.

When I click the commandbutton "Create Budget", it works in the background, it creates the budget, but the VF page does not refresh to show me the new budget related list.

Any help?

My VF page
<apex:page standardController="CCI_Project__c" extensions="budAddBudget">
    <apex:form>
    <apex:pageblock>
     <apex:pageblockButtons location="top">
                 <apex:commandButton value="Create Budget" action="{!addBudget}" reRender="bp"/>
            </apex:pageblockButtons>
     </apex:pageblock>
        <apex:outputPanel id="bp">
         <apex:repeat value="{!project}" var="p">
            <apex:pageBlock>
                <apex:pageBlockSection >
                    <apex:outputField value="{!p.Name}"/>
                    <apex:outputField value="{!p.Closed_Opportunity__c}"/>
                </apex:pageBlockSection>
        
                <apex:pageBlockTable value="{!p.Budgets__r}" var="b">
                    <apex:column value="{!b.Name}"/>
                    <apex:column value="{!b.Start_Date__c}"/>
                    <apex:column value="{!b.Total_Budget__c}"/>
                    <apex:column value="{!b.Total_Actual__c}"/>
                    <apex:column value="{!b.Total_Invoiced_to_Date__c}"/>
                </apex:pageBlockTable>
         
           
        </apex:pageBlock>
     </apex:repeat>
      </apex:outputpanel>
    </apex:form>
</apex:page>
The controlling class
public PageReference addBudget() {
        // Do code
        this.prj = (CCI_Project__c)standardController.getRecord();
        
        system.debug ('projId ' +prj.id);
        system.debug('a');

        proj = [Select ID, Name, Closed_Opportunity__c From CCI_Project__c Where Id=:prj.Id];
        // Call budgetAdd Method in class createBudget
            cb.budgetAdd(proj.id, proj.Closed_Opportunity__c);


        
        
        
        
        return null;
    
    }

Any suggestions GREATLY appreciated.
 
Best Answer chosen by Hugo Stoupe
surasura
rerender doesnt work with methods have return type PageRefrence as it reload the entire page.

try this 
 
public void addBudget() {
        // Do code
        this.prj = (CCI_Project__c)standardController.getRecord();
        
        system.debug ('projId ' +prj.id);
        system.debug('a');

        proj = [Select ID, Name, Closed_Opportunity__c From CCI_Project__c Where Id=:prj.Id];
        // Call budgetAdd Method in class createBudget
            cb.budgetAdd(proj.id, proj.Closed_Opportunity__c);


        
        
        
        
       
    
    }

I am not very clear about the code you have but I hope your create method add the new record to the list

All Answers

surasura
rerender doesnt work with methods have return type PageRefrence as it reload the entire page.

try this 
 
public void addBudget() {
        // Do code
        this.prj = (CCI_Project__c)standardController.getRecord();
        
        system.debug ('projId ' +prj.id);
        system.debug('a');

        proj = [Select ID, Name, Closed_Opportunity__c From CCI_Project__c Where Id=:prj.Id];
        // Call budgetAdd Method in class createBudget
            cb.budgetAdd(proj.id, proj.Closed_Opportunity__c);


        
        
        
        
       
    
    }

I am not very clear about the code you have but I hope your create method add the new record to the list
This was selected as the best answer
shiva pendemshiva pendem
HI Hugo,

Can you please try this code..

<apex:page standardController="CCI_Project__c" extensions="budAddBudget">
    <apex:form>
    <apex:pageblock>
     <apex:pageblockButtons location="top">
                 <apex:commandButton value="Create Budget" action="{!addBudget}" reRender="bp,pb"/>
            </apex:pageblockButtons>
     </apex:pageblock>
        <apex:outputPanel id="bp">
         <apex:repeat value="{!project}" var="p">
            <apex:pageBlock id="pb">
                <apex:pageBlockSection >
                    <apex:outputField value="{!p.Name}"/>
                    <apex:outputField value="{!p.Closed_Opportunity__c}"/>
                </apex:pageBlockSection>
        
                <apex:pageBlockTable value="{!p.Budgets__r}" var="b">
                    <apex:column value="{!b.Name}"/>
                    <apex:column value="{!b.Start_Date__c}"/>
                    <apex:column value="{!b.Total_Budget__c}"/>
                    <apex:column value="{!b.Total_Actual__c}"/>
                    <apex:column value="{!b.Total_Invoiced_to_Date__c}"/>
                </apex:pageBlockTable>
         
           
        </apex:pageBlock>
     </apex:repeat>
      </apex:outputpanel>
    </apex:form>
</apex:page>


Thanks,
Shiva