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
Ajay Patel 30Ajay Patel 30 

'onchange' event of supportaction is not working properly

Hi,

I have one object (business__c), it has two fields(session__c and timing__c) and both the fields are dependent field.
The timing__c field depends on the session__c field.
So i have created a visulforce page to achieve some functionality but onchnge field on actionsupport is not working properly means when user is selecting "Second Slot" from session__c field and timing__c field automatically populated as"3hrs" but it is not displaying any record in table(pageblocktable).

Controller Class:
public with sharing class Business_class{
           
           public List<business__c> businessDetailslist{get;set;}
           public business__c businessDetails {get;set;}
           public string timingsession{get;set;}
           
      public Business_class(ApexPages.StandardController controller){
              
            businessDetails = new business__c();
            
     }

    public void searchBusinessDeatils(){     
            
            businessDetailslist = [Select session__c,timing__c,description__c from business__c where timing__c =:timingsession limit 1];
       }
            
      
     public List<SelectOption> getItems() {
       
        List<SelectOption> options = new List<SelectOption>();    
               if(businessDetails.session__c=='First Slot'){
                    options.add(new SelectOption('5hrs','5hrs'));
                    options.add(new SelectOption('7hrs','7hrs'));
                 }
              else if(businessDetails.session__c=='Second Slot'){
                    options.add(new SelectOption('3hrs','3hrs'));
                  }

         return options;
    }
  
    
   }
  

Visualforce Page:

<apex:page standardController="contact" extensions="Business_class" sidebar="false">
<apex:form id="frm1">
      <apex:actionFunction name="srchfun" reRender="section_1"/>
      
           <apex:pageBlock title="{!$Label.details}" id="pbid" rendered="{!ShowBlock==true}">\
               <apex:pagemessages id="msg"/>
               <apex:pageBlockSection columns="2" id="cmid">
                
                      <apex:pageBlockSectionItem id="sctnid1">
                           <apex:outputLabel value="{!$Label.Session_name}"></apex:outputLabel>
                           <apex:inputField value="{!businessdetails.session__c}">
                           <apex:actionSupport event="onchange"  rerender="serchdetails,timingdat" status="counterStatus"/>
                           </apex:inputField>
                       
                     </apex:pageBlockSectionItem>
                    
                     <apex:pageBlockSectionItem id="sctnid2">
                        <apex:outputlabel value="{!$Label.Timing_slot}" />
                        <apex:outputPanel id="timingdat">
                             <apex:actionRegion >
                                <apex:selectList value="{!timingsession}" size="1" >
                                  <apex:selectOptions value="{!Items}"/>
                                  <apex:actionSupport event="onchange" rerender="serchdetails" status="counterStatus"  action="{!searchBusinessDeatils}"/>                                 
                               </apex:selectList>
                             </apex:actionRegion>
                       </apex:outputPanel>
                     </apex:pageBlockSectionItem>   
               </apex:pageBlockSection>
      
            <br/>
        <apex:outputPanel id="serchdetails">
          <apex:pageBlockTable value="{!businessDetailslist}" var="bdrt" id="istable" columns="3" >
                <apex:column headerValue="{!$Label.Session_name}">
                    <apex:outputField value="{!bdrt.session__c }"/>
                </apex:column>
                <apex:column headerValue="{!$Label.Timing_slot}">
                    <apex:outputField value="{!bdrt.timing__c}"/>
                </apex:column>
                <apex:column headerValue="{!$Label.Description}">
                    <apex:outputField value="{!bdrt.description__c}"/>
                </apex:column>
            </apex:pageBlockTable>
        </apex:outputPanel>
        </apex:pageBlock>
        
</apex:form>
</apex:page>
              


Can any help me on this.

Thanks in adv.
GauravendraGauravendra
Hi Ajay,

I think action support is working fine. As onchange event require user interaction. If you change from UI, it will work. As the changes are done by code, it is not reflecting.

One aproach you can opt for is adding '--None--' as first dropdown in both the cases. So, if you choose first slot or second slot, timing dropdown requires user interaction for change. In that case pageblock table will populate accordingly.
public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();    
               if(businessDetails.session__c=='First Slot'){
                   options.add(new SelectOption('None','None'));
                    options.add(new SelectOption('5hrs','5hrs'));
                    options.add(new SelectOption('7hrs','7hrs'));
                 }
              else if(businessDetails.session__c=='Second Slot'){
                  options.add(new SelectOption('None','None'));
                    options.add(new SelectOption('3hrs','3hrs'));
                  }
         return options;
    }

Hope this helps.
Dushyant SonwarDushyant Sonwar
Ajay ,

1) Try changing your below actionSupport line
<apex:actionSupport event="onchange" rerender="serchdetails" status="counterStatus"  action="{!searchBusinessDeatils}"/>

to
<apex:actionSupport event="onchange" rerender="serchdetails,msg" status="counterStatus"  action="{!searchBusinessDeatils}"/>
2) Put a System.debug(timingsession + ' @@@@@ ' + businessDetailslist)  at your searchBusinessDeatils method to check for any issue.


Hope this helps.
 
Ajay Patel 30Ajay Patel 30
Hi Dushyant,

Thanks for your suggestion.
I have made the change according to you, but still i'm facing same issue.

Thanks
Dushyant SonwarDushyant Sonwar
Hi Ajay,
If you are not getting the debug then,
Remove ActionRegion tag and use immediate attribute.
<apex:actionSupport event="onchange" rerender="serchdetails,msg" status="counterStatus"  action="{!searchBusinessDeatils}" immediate="true"/>

 
Ajay Patel 30Ajay Patel 30
Hi Dushyant,

I'm still not getting any debug statement in debug logs after adding of immediate attribute.

Thanks

 
Dushyant SonwarDushyant Sonwar
Hi Ajay ,

I think i got your issue. Your Timing slot picklist  is empty . when you try to change value in timing picklist , that time your event does not fire because your timing slot has not been changed.
Try to comment out the below condition then put a  debug on your searchBusinessDeatils method and check if method is being called or not. 
public List<SelectOption> getItems() {
       
        List<SelectOption> options = new List<SelectOption>();    
              // if(businessDetails.session__c=='First Slot'){
                    options.add(new SelectOption('5hrs','5hrs'));
                    options.add(new SelectOption('7hrs','7hrs'));
             //    }
             // else if(businessDetails.session__c=='Second Slot'){
                    options.add(new SelectOption('3hrs','3hrs'));
               //   }

         return options;
    }