0
<apex:page controller="CreateExaminationController" >
    <apex:form >
        <apex:pageblock >
            <apex:pageblocksection >
                <apex:pageblockSectionItem >Course : </apex:pageblockSectionItem>
                <apex:pageblocksectionItem >
                    <apex:selectList value="{!selectedCourse}" size="1">
                        <apex:selectOptions value="{!AllCourses}"></apex:selectOptions>
                        <apex:actionSupport event="onchange" reRender="blockSubjects"/>
                    </apex:selectList>
                </apex:pageblocksectionItem>
            </apex:pageblocksection>

            <apex:pageblocksection id="blockSubjects" >
                <apex:pageblockSectionItem >Subjects : </apex:pageblockSectionItem>
                <apex:pageblocksectionItem >
                    <apex:selectList value="{!selectedSubject}" size="1">
                        <apex:selectOptions value="{!CourseSubject}"></apex:selectOptions>
                        <apex:actionSupport event="onchange" reRender="studentSubjectTable"/>
                    </apex:selectList>
                </apex:pageblocksectionItem>
            </apex:pageblocksection>
        </apex:pageblock>

        <apex:pageblock >
            <apex:pageblockbuttons >
                <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="studentSubjectTable" />
            </apex:pageblockbuttons>
            <apex:pageblockTable id="studentSubjectTable" value="{!contacts}" var="item">
                <apex:column >
                    <apex:inputCheckbox value="{!item.selected}" />
                </apex:column>
                <apex:column value="{!item.con.Name}"/>
                <apex:column value="{!item.con.Email}"/>
                <apex:column value="{!item.con.Phone}"/>
            </apex:pageblockTable>
        </apex:pageblock>

    </apex:form>
</apex:page>

I want to rerender PageBlockTable studentSubjectTable on change of SelectList selectedSubject as well as on click of Button processSelected. But now, the PageBlockTable only rerenders after I click processSelected Button.

  • wrap pageblock in outputPanel and assign a id to it. Rerender the outputPanel. It should work – Rohit Mourya May 23 '17 at 13:23
  • @RohitMourya Unfortunately it's still not working. I still have to press the Process Selected button after selecting the values from Dropdown. – Krishnandu Sarkar May 24 '17 at 5:10
1

Define an id of the pageBlock (e.g. pgstudentSubjectId) and try to rerender from actionSupport and Commandbutton, instead of rendering the pageBlockTable. It should work.

<apex:selectList value="{!selectedSubject}" size="1">
       <apex:selectOptions value="{!CourseSubject}"></apex:selectOptions>
       <apex:actionSupport event="onchange" reRender="pgstudentSubjectId"/>
</apex:selectList>

<apex:pageblock id="pgstudentSubjectId">
    <apex:pageblockbuttons >
        <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="pgstudentSubjectId" />
    </apex:pageblockbuttons>
    <apex:pageblockTable id="studentSubjectTable" value="{!contacts}" var="item">
        <apex:column >
            <apex:inputCheckbox value="{!item.selected}" />
        </apex:column>
        <apex:column value="{!item.con.Name}"/>
        <apex:column value="{!item.con.Email}"/>
        <apex:column value="{!item.con.Phone}"/>
    </apex:pageblockTable>
</apex:pageblock>
  • Unfortunately It's not working that way :( – Krishnandu Sarkar May 24 '17 at 5:10
  • This should work as along as you dont put rendered condition is PageBlock table. If you put rendered condition then pageblock must be wrapped with outputPanel which is not with rendered condition. Bottom line is, pageblock or outputPanel must be visible when actionSupport is trying to rerender the pageblock or outputPanel. Makes sense? – Santanu Boral May 24 '17 at 13:42
  • Can you please accept my answer so that others will find useful – Santanu Boral May 25 '17 at 11:54
0

I found the solution from : Rerender pageblock on change of picklist

I'm posting my code here for future reference.

<apex:page controller="CreateExaminationController" >
    <apex:form >
        <apex:pageblock title="Course & Subject">
            <apex:pageblocksection >
                <apex:pageblockSectionItem ><apex:outputLabel >Course</apex:outputLabel></apex:pageblockSectionItem>
                <apex:pageblocksectionItem >
                    <apex:selectList value="{!selectedCourse}" size="1">
                        <apex:selectOptions value="{!AllCourses}"></apex:selectOptions>
                        <apex:actionSupport event="onchange" reRender="blockSubjects"/>
                    </apex:selectList>
                </apex:pageblocksectionItem>
            </apex:pageblocksection>

            <apex:pageblocksection id="blockSubjects" >
                <apex:pageblockSectionItem ><apex:outputLabel >Subject</apex:outputLabel></apex:pageblockSectionItem>
                <apex:pageblocksectionItem >
                    <apex:selectList value="{!selectedSubject}" size="1">
                        <apex:selectOptions value="{!CourseSubject}"></apex:selectOptions>
                        <apex:actionSupport event="onchange" reRender="studentSubjectTableBlock"/>
                    </apex:selectList>
                </apex:pageblocksectionItem>
            </apex:pageblocksection>
        </apex:pageblock>

        <apex:outputPanel id="studentSubjectTableBlock">
            <apex:pageblock title="Students" rendered="{!selectedSubject != null}">
                <apex:pageblockbuttons >
                    <apex:commandButton value="Process Selected" action="{!processSelected}" rerender="studentSubjectTable" />
                </apex:pageblockbuttons>
                <apex:pageblockTable value="{!contacts}" var="item" id="studentSubjectTable">
                    <apex:column >
                        <apex:inputCheckbox value="{!item.selected}" />
                    </apex:column>
                    <apex:column value="{!item.con.Name}"/>
                    <apex:column value="{!item.con.Email}"/>
                    <apex:column value="{!item.con.Phone}"/>
                </apex:pageblockTable>
            </apex:pageblock>
        </apex:outputPanel>
    </apex:form> 
</apex:page>

Please note the usage of rendered in PageBlock

  • you have put the rendered condition in pageblock thats why it has to be wrapped with outputPanel which doesn't have rendered condition. – Santanu Boral May 24 '17 at 13:44

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.