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
Nathan BortonNathan Borton 

apex:commandbutton not rerendering pageblocktable

Hey all. I'm having some trouble getting a commandButton to rerender a pageBlockTable which is inside an outputPanel that is always renderered

<apex:page controller="AirlockLookup" lightningStylesheets="true" showHeader="false" sidebar="false">
    <apex:form id="form">
            <apex:pageBlock id="block">
                <apex:pageBlockSection id="section1" columns="1">
                    <h1 style="font-size:18px;text-align:center;">Airlock Model Search</h1>
                </apex:pageBlockSection>
                <apex:pageBlockSection id="section2" columns="2">
                    <apex:inputText id="Make" label="Make" value="{!Make}" title="Leave Blank if Unknown">
                        <apex:actionSupport reRender="section2" event="onchange" />
                    </apex:inputText>
                    <apex:inputText label="OEM" value="{!OEM}" rendered="{!(Make == 'RAS')}" title="Leave Blank if Unknown"/>
                    <apex:inputText label="Series" value="{!Series}" title="Leave Blank if Unknown"/>
                    <apex:inputText label="Model Name" value="{!ModelName}" title="Leave Blank if Unknown"/>
                    <apex:selectList label="Flange Style" value="{!FlangeStyle}" size="1">
                        <apex:selectOption itemLabel="Unknown" itemValue="Unknown" title="Unknown"/>
                        <apex:selectOption itemLabel="Square" itemValue="Square" title="Square"/>
                        <apex:selectOption itemLabel="Round" itemValue="Round" title="Round"/>
                        <apex:selectOption itemLabel="Square Inlet/Round Outlet" itemValue="Square Inlet/Round Outlet" title="Square Inlet/Round Outlet"/>
                        <apex:selectOption itemLabel="Round Inlet/Square Outlet" itemValue="Round Inlet/Square Outlet" title="Round Inlet/Square Outlet"/>
                    </apex:selectList>
                    <apex:selectList label="Endcap Configuration" value="{!ECConfig}" size="1">
                        <apex:selectOption itemLabel="Unknown" itemValue="Unknown" title="Unknown"/>
                        <apex:selectOption itemLabel="Inboard" itemValue="Inboard" title="Inboard" />
                        <apex:selectOption itemLabel="Outboard" itemValue="Outboard" title="Outboard" />
                    </apex:selectList>
                    <apex:selectList label="Product Passage" value="{!ProductPassage}" size="1">
                        <apex:selectOption itemLabel="Unknown" itemValue="Unknown" title="Unknown"/>
                        <apex:selectOption itemLabel="Blow Thru" itemValue="Blow Thru" title="Blow Thru"/>
                        <apex:selectOption itemLabel="Drop Thru" itemValue="Drop Thru" title="Drop Thru"/>
                        <apex:selectOption itemLabel="Jet-Under" itemValue="Jet-Under" title="Jet-Under"/>
                        <apex:selectOption itemLabel="Offset" itemValue="Offset" title="Offset"/>
                    </apex:selectList>
                    <apex:selectList label="Cleaning Options" value="{!CleaningOptions}" size="1">
                        <apex:selectOption itemLabel="None" itemValue="None" title="None"/>
                        <apex:selectOption itemLabel="Quick Clean" itemValue="Quick Clean" title="Quick Clean"/>
                        <apex:selectOption itemLabel="Clean in Place" itemValue="Clean in Place" title="Clean in Place"/>
                    </apex:selectList>
                    <apex:selectList label="Housing Inspection Door?" value="{!HID}" size="1">
                        <apex:selectOption itemLabel="No" itemValue="No" title="No"/>
                        <apex:selectOption itemLabel="Yes" itemValue="Yes" title="Yes"/>
                    </apex:selectList>
                    <apex:selectList label="Steam Water Jacketed Endcaps?" value="{!SWJEndcaps}" size="1">
                        <apex:selectOption itemLabel="No" itemValue="No" title="No"/>
                        <apex:selectOption itemLabel="Yes" itemValue="Yes" title="Yes"/>
                    </apex:selectList>
                    <apex:selectList label="Steam Water Jacketed Housing?" value="{!SWJHousing}" size="1">
                        <apex:selectOption itemLabel="No" itemValue="No" title="No"/>
                        <apex:selectOption itemLabel="Yes" itemValue="Yes" title="Yes"/>
                    </apex:selectList>                    
                    <br/>
                </apex:pageBlockSection>
                <apex:pageBlockSection columns="1">
                    <apex:commandButton title="Search for Models" value="Search" action="{!SearchModels}" reRender="models" status="searchstatus"/>
                    <apex:actionStatus id="searchstatus" >
                        <apex:facet name="start">
                            <div style="position: fixed; top: 0; left: 0; right: 0; bottom: 0; opacity: 0.75; z-index: 1000; background-color: black;">
                                &nbsp;
                            </div>
                            <div style="position: fixed; left: 0; top: 0; bottom: 0; right: 0; z-index: 1001; margin: 30% 50%">
                                <img src="http://upload.wikimedia.org/wikipedia/commons/e/ed/Cursor_Windows_Vista.gif" />
                            </div>
                        </apex:facet>
                    </apex:actionStatus>
                    <apex:outputPanel id="models">
                        <apex:pageBlockTable value="{!models}" var="m" rendered="{!showModels}">
                            <apex:column headerValue="Model Name" value="{!m.Name}" />
                            <apex:column headerValue="Make" value="{!m.Make_Name__c}" />
                        </apex:pageBlockTable>
                    </apex:outputPanel>
                </apex:pageBlockSection>
            </apex:pageBlock>
    </apex:form>
    
</apex:page>
 
public class AirlockLookup {
    public String Make {get; set;}
    public Boolean showOEM {get; set{showOEM = false;}}
    public String OEM {get; set;} // Only if Make is RAS
    public String Series {get; set;} // Dependent on Make
    public String ModelName {get; set;} // Will need to use a Contains()
    public String FlangeStyle {get; set;} // Square, Round, Square Inlet/Round Outlet, Square Outlet/Round Inlet
    public String ProductPassage {get; set;} // Blow Thru, Drop Thru, Jet-Under, Offset
    public String ECConfig {get; set;} // Inboard, Outboard
    public String CleaningOptions {get; set;} // None, Quick Clean, Clean in Place
    public Decimal HousingHeight {get; set;} 
    public String HID {get; set;} // Housing Inspection Door: Yes, No
    public Decimal AIFlangeID {get; set;}
    public Decimal AIFlangeOD {get; set;}
    public Decimal RIFlangeID {get; set;}
    public Decimal RIFlangeOD {get; set;}
    public Decimal IFlangeID {get; set;}
    public Decimal IFlangeOD {get; set;} // All Decimal fields are 14 left, 4 right
    public Decimal AOFlangeID {get; set;}
    public Decimal AOFlangeOD {get; set;}
    public Decimal ROFlangeID {get; set;}
    public Decimal ROFlangeOD {get; set;}
    public Decimal OFlangeID {get; set;}
    public Decimal OFlangeOD {get; set;}
    public String SWJEndcaps {get; set;} // Steam Water Jacketed Endcaps: Yes, No
    public String SWJHousing {get; set;} // Steam Water Jacketed Housing: Yes, No
    public List<Model__c> models {get; set{models = new List<Model__c>();}}
    public Boolean showModels {get; set{showModels = false;}}
    
	public AirlockLookup() {
        
    }
    
    public PageReference SearchModels() {
        showModels = true;
        models = [SELECT Id, Name, Make_Name__c, OEM_Style__c, Series__c, Flange_Style__c, Product_Passage__c, Endcap_Configuration__c, Cleaning_Options__c, Housing_Height__c,
                 Housing_Inspection_Door__c, Axial_Inlet_Flange_ID__c, Axial_Inlet_Flange_OD__c, Radial_Inlet_Flange_ID__c, Radial_Inlet_Flange_OD__c, Inlet_Flange_ID__c,
                 Inlet_Flange_OD__c, Axial_Outlet_Flange_ID__c, Axial_Outlet_Flange_OD__c, Radial_Outlet_Flange_ID__c, Radial_Outlet_Flange_OD__c, Outlet_Flange_ID__c,
                 Outlet_Flange_OD__c, Steam_Water_Jacketed_Endcaps__c, Steam_Water_Jacketed_Housing__c FROM Model__c WHERE Make_Name__c = :Make];
        		
        return null;
    }
}
Best Answer chosen by Nathan Borton
Nathan BortonNathan Borton
I figured it out. Apparently it reinitializes the variables in the apex class everytime I do a rerender because they are being set in their respective {get; set;} so I just moved the initializations to the constructor and now it is rendering just fine

All Answers

Abhishek BansalAbhishek Bansal
Hi,

Can you try changing the id to modelsId and if this also doesn't work then try reRendering the whole form using reRender="form".

Let me know if need more help on this.

Thanks,
Abhishek Bansal.
Nathan BortonNathan Borton

Abhishek,

Tried doing both and i'm still getting the same result

Nathan BortonNathan Borton
I figured it out. Apparently it reinitializes the variables in the apex class everytime I do a rerender because they are being set in their respective {get; set;} so I just moved the initializations to the constructor and now it is rendering just fine
This was selected as the best answer