[SalesForce] PageBlockTable not reRendering correctly after commandButton click

I has to reRender the pageblocktable after commandButton click. I am displaying custom object values in a pageblocktable. There is another pageblock to insert new record into the object along with a commandButton. Now i have to reRender the pageBlocktable to populate new values. I am using reRender attribute to refresh the pageBlockTable but no luck.

Visualforce Page:

<apex:page controller="orgtestController">
<apex:form >
    <apex:pageBlock >
        <apex:outputPanel id="a">
        <apex:pageBlockTable columns="4" value="{!orgDetails}" var="a" rendered="true">
            <apex:column value="{!a.id}"/>
            <apex:column value="{!a.name}"/>
            <apex:column value="{!a.totalsalary__c}"/>
        </apex:pageBlockTable>
        </apex:outputPanel>
        <apex:pageBlock >
            <apex:pageBlockSection title="Enter new Organization">
                <apex:outputPanel >
                        <apex:panelGrid columns="2" rendered="true"> 
                            <apex:outputLabel >Name</apex:outputLabel>    
                            <apex:inputText value="{!orgName}"/>
                            <apex:outputLabel >Total Salary</apex:outputLabel>    
                            <apex:inputText value="{!orgTotal}"/>
                            <apex:commandButton value="Create" action="{!create}" reRender="a"/>
                        </apex:panelGrid> 
                </apex:outputPanel>
            </apex:pageBlockSection>              
        </apex:pageBlock>
    </apex:pageBlock>
</apex:form>
</apex:page>

Controller :

 public with sharing class orgtestController {
   public PageReference create() {
     organization__c newOrg = new organization__c(); 
     newOrg.name=orgName ;
     newOrg.totalsalary__c=orgTotal;
     insert newOrg;
    return null;
 }
 public Integer orgTotal { get; set; }
 public String orgName { get; set; }
 public List<organization__c> orgDetails { get; set; }
 public orgtestController()
 {
    orgDetails =new List<organization__c>();
    for(List<organization__c> org:[select id,name,totalsalary__c from organization__c])
    {
        orgDetails=org;
    }
 }
}

could any one figure it where i am doing wrong

Best Answer

I changed my controller to run succesfully

public with sharing class orgtestController {
public orgtestController() {

}
public PageReference create() {
     renders=true;
     organization__c newOrg = new organization__c(); 
     newOrg.name=orgName ;
     newOrg.totalsalary__c=orgTotal;
     insert newOrg;
     return null;
}
public Integer orgTotal { get; set; }
public String orgName { get; set; }
public List<organization__c> getorgDetails()
{
    List<organization__c> orgDetails =new List<organization__c>();
    for(List<organization__c> org:[select id,name,totalsalary__c from organization__c])
    {
        orgDetails=org;
    }
    return orgDetails;
}
public orgtestController (String name,Integer total)
{
    this.orgTotal =total;
    this.orgName=name;
}
}
Related Topic