You need to sign in to do that
Don't have an account?
community
Display command button when any picklist value is selected.
Hi,
Im struggling with the actionSupport function in visualforce.
If the picklist value of 'Address_Type__c' is other than None , then the command button should be displayed.
Visualforce page:
<apex:page standardController="Address_Details__c" extensions="CRFNewAddressSelect"> <apex:form > <apex:sectionHeader Title="Address Details" /> <apex:pageBlock Title="Select the type of Address"> <apex:pageBlockSection columns="1"> <apex:PageBlockSectionItem > <apex:outputLabel value="{!$ObjectType.Address_Details__c.fields.Address_Type__c.label}"/> <apex:selectList id="id_1" value="{!Address_Details__c.Address_Type__c}" size="1" > <apex:actionSupport event="onchange" reRender="ajaxrequest" immediate="True"/> <apex:selectOptions value="{!items}"/> </apex:selectList> </apex:PageBlockSectionItem> <apex:PageBlockSectionItem > <apex:outputPanel id="ajaxrequest" rendered="{!disp}"> <apex:commandButton value="Continue"/> </apex:outputPanel> </apex:PageBlockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Controller:
public with sharing class CRFNewAddressSelect { private Address_Details__c AD; public CRFNewAddressSelect(ApexPages.StandardController stdcontroller) { this.AD=(Address_Details__c)stdController.getRecord(); } Boolean disp=False; Public Boolean getdisp(){ return disp; } String Values; public String getValues() { return Values; } public void setValues(String Values) { this.Values= Values; if(Values!=null) disp=True; } public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('None','None')); options.add(new SelectOption('CA','Cease Address')); options.add(new SelectOption('CANADA','Canada')); options.add(new SelectOption('MEXICO','Mexico')); return options; } }
I tried everything possible. Its not working. For text fields my code does work, but for picklist, I think I am missing something. Help
Ah yes - this section:
Doesn't appear to be tied into the page, so disp is never being updated to true.
You should be able to handle this without recourse to the controller. Simply render your button based on the selected value, which will be stored in Address_Details__c.Address_Type__c, e.g.
All Answers
You have specified immediate="True" on your actionsupport - this means that your selected value will be discarded rather than propagated back to the controller.
You may also hit problems with rerendering the ajaxrequest outputpanel if it wasn't present when the page was originally drawn - I've written a blog post on this at:
http://bobbuzzard.blogspot.com/2011/02/visualforce-re-rendering-woes.html
Thanks for the reply. I added the output panel container to the existing one and removed immediate = true from the actionSupport, but still it doesn't work.
Is there anything going wrong in the controller ?
Thanks!
Ah yes - this section:
Doesn't appear to be tied into the page, so disp is never being updated to true.
You should be able to handle this without recourse to the controller. Simply render your button based on the selected value, which will be stored in Address_Details__c.Address_Type__c, e.g.
Thanks a ton mate!It worked awesome!!!! :)
Infact it was
for null values.
Cheers!