You need to sign in to do that
Don't have an account?
Ajay 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.
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.
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.
Hope this helps.
1) Try changing your below actionSupport line
to
2) Put a System.debug(timingsession + ' @@@@@ ' + businessDetailslist) at your searchBusinessDeatils method to check for any issue.
Hope this helps.
Thanks for your suggestion.
I have made the change according to you, but still i'm facing same issue.
Thanks
If you are not getting the debug then,
Remove ActionRegion tag and use immediate attribute.
I'm still not getting any debug statement in debug logs after adding of immediate attribute.
Thanks
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.