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
raysfdc1988raysfdc1988 

Rerender visualforce when an item from a picklist is selected

<apex:page controller="BookRoom" docType="html-5.0" >

<apex:form >

<apex:pageBlock  >
<apex:pageMessages id="msg"></apex:pageMessages>
////////This Is Picklist field/////////////////
<apex:outputtext ><b>Room No</b></apex:outputtext>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<apex:inputField value="{!dx.Room__c}" rendered="true" required="true"></apex:inputField>
<br></br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
<apex:outputText escape="true"><b>Date</b></apex:outputText>
<apex:inputfield value="{!dummyroom.Date__c}" required="true" rendered="true" /></br>
<apex:outputtext ><b>Client Name</b></apex:outputtext>
<apex:inputfield value="{!dx.Contact__c}" required="true"  label="Client Name" />
<br/>
<apex:commandButton value="Check Availability" action="{!CheckAvailability}" rendered="true"/>
<br/>
</apex:pageBlock>
/////////////////////////////////////////////////////////////////////////

<apex:pageBlock rendered="{!ShowpageBlockFlag}">
<apex:dataTable value="{!BookingSlots}" var="bs" id="thetable" columnClasses="col1,col2,col3,col4" width="60%">
<apex:column value="{!bs.event.subject}"/>
<apex:column value="{!bs.event.startdatetime}"/>
<apex:column value="{!bs.event.enddatetime}"/>
<apex:column ><apex:inputCheckbox value="{!bs.checkbox}" required="true"/></apex:column>
</apex:dataTable>
<br/><br/><br/>

<apex:commandButton value="Book the slot" action="{!Savedetails}" rerender="msg,ol"/>
<apex:commandButton value="Cancel" action="{!Cancel}" rerender="msg,pl"/>
</apex:pageBlock>

 

</apex:form>
</apex:page>
I want Rerender the first pageblock after item from picklist is changed...


Madhura BMadhura B

Hi,

From your code it is hard to say which one is the picklist you are referring to. 
You can refer to the below sample code and apply the same in your code
 

<apex:PageBlock>

<apex:pageBlockSection>          
  <!-- Your picklist field will be here, onchange event should rerender the desired section-->
       <apex:inputField value="{!object.Picklist}">
              <apex:actionSupport event="onchange" reRender="dTable" />
        </apex:inputField>
</apex:pageBlockSection>

<apex:pageblockSection id="dTable">
       <apex:dataTable>
    
        </apex:dataTable>   
</apex:pageblockSection>

</apex:pageBlock>

I would suggest you use one pageblock and different pageblockSections. Using multiple pageblocks in a single page is not a good practice


If this resolves your issue, please mark this as the answer

Thanks

Grazitti TeamGrazitti Team
Hi, 

You can achive this with the help of below code.

Apex Class:

Public Class TestController{
    Public roomName{get;set;}
     
    public TestController (){
        roomName  = [Select id, [fieldName] form [CustomObjectName] Limit 1].fieldName; 
    }

	public List<SelectOption> getRoom(){
        List<SelectOption> roomSelectOptionList   = new SelectOption();
        for (Schema.PicklistEntry f : [CustomObjectName].[FieldName].getDescribe().getPicklistValues()) {
               roomSelectOptionList.add(new SelectOption(f.getValue(),f.getLabel()));
        }
        return roomSelectOptionList;
    }

}

VF Page:

<apex:page controller="BookRoom" docType="html-5.0" >

<apex:form >

<strong><apex:pageBlock  ></strong>
<apex:pageMessages id="msg"></apex:pageMessages>
////////This Is Picklist field/////////////////
<strong><apex:outputtext ><b>Room No</b></apex:outputtext>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<apex:selectList value="{!roomName }" size="1" >
	<apex:actionSupport event="onchange" reRender="pageBlockPanel" />
	<apex:selectOptions value="{!Room}"/>
</apex:selectList>
<br></br></strong>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
<apex:outputText escape="true"><b>Date</b></apex:outputText>
<apex:inputfield value="{!dummyroom.Date__c}" required="true" rendered="true" /></br>
<apex:outputtext ><b>Client Name</b></apex:outputtext>
<apex:inputfield value="{!dx.Contact__c}" required="true"  label="Client Name" />
<br/>
<apex:commandButton value="Check Availability" action="{!CheckAvailability}" rendered="true"/>
<br/>
<strong></apex:pageBlock></strong>
/////////////////////////////////////////////////////////////////////////

<apex:outputPanel id ="pageBlockPanel">
	<apex:pageBlock rendered="{!ShowpageBlockFlag}">
	<apex:dataTable value="{!BookingSlots}" var="bs" id="thetable" columnClasses="col1,col2,col3,col4" width="60%">
	<apex:column value="{!bs.event.subject}"/>
	<apex:column value="{!bs.event.startdatetime}"/>
	<apex:column value="{!bs.event.enddatetime}"/>
	<apex:column ><apex:inputCheckbox value="{!bs.checkbox}" required="true"/></apex:column>
	</apex:dataTable>
	<br/><br/><br/>

	<apex:commandButton value="Book the slot" action="{!Savedetails}" rerender="msg,ol"/>
	<apex:commandButton value="Cancel" action="{!Cancel}" rerender="msg,pl"/>
	</apex:pageBlock>
<apex:outputPanel>

 

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

Please mark as best answer if it solves your problem.

Regards,
Grazitti Team,