You need to sign in to do that
Don't have an account?
steve_andersen
Differential page display: having trouble with radio button driving section visibility
<meta name="GENERATOR" content="BLOCKNOTE.NET">BODY { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
P { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
DIV { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
TD { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
and here is the part of the page I want to render:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="GENERATOR" content="BLOCKNOTE.NET">BODY { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
P { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
DIV { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
TD { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
In my controller I've got a String set up to catch the Radio values:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="GENERATOR" content="BLOCKNOTE.NET">BODY { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
P { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
DIV { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
TD { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
And in my constructor, I'm setting oppApplicant if I have a querystring variable:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="GENERATOR" content="BLOCKNOTE.NET">BODY { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
P { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
DIV { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
TD { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
I'll paste the full code of the controller and page below. Thanks for any help!
Full Page:
Full Controller:
I'm trying to do a dynamic page section like Jon outlined here, but I'm having trouble.
I want a user to select a radio, and then display a page section based on that value. I can get the section to render based on the conditional, but I can't get it to change when the radio button is changed. I'm clearly missing something.
Here is my radio:<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="GENERATOR" content="BLOCKNOTE.NET">
BODY { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
P { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
DIV { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
TD { FONT-FAMILY:Verdana; FONT-SIZE:10pt }
<apex:actionRegion > <apex:outputPanel > <apex:outputLabel value="Apply Opportunity To" for="oppApplicantSelect"/> <apex:selectRadio id="oppApplicantSelect" value="{!oppApplicant}"> <apex:selectOption itemValue="Contact" itemLabel="Contact"/> <apex:selectOption itemValue="Organization" itemLabel="Organization"/> <apex:actionSupport event="onchange" rerender="orgSection" status="status"/> </apex:selectRadio> <apex:actionStatus startText="applying value...{!oppApplicant}" id="status"/> </apex:outputPanel> </apex:actionRegion>
and here is the part of the page I want to render:
<apex:pageBlock title="Organization info" id="orgSection" rendered="{!oppApplicant == 'Organization'}"> <apex:outputLabel value="Organization" for="accountField"/> <apex:inputField id="accountField" value="{!opportunity.AccountId}"/> <apex:outputText value="{!oppApplicant}"/> </apex:pageBlock>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="GENERATOR" content="BLOCKNOTE.NET">
Code:
public String oppApplicant { get {return oppApplicant;} set {oppApplicant = value;} }
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="GENERATOR" content="BLOCKNOTE.NET">
Code:
if(ApexPages.currentPage().getParameters().get('contactId')!=null) { oppApplicant = 'Contact'; } else { oppApplicant = 'Organization'; }
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="GENERATOR" content="BLOCKNOTE.NET">
Steve
Full Page:
Code:
<apex:page standardController="Opportunity" tabStyle="Opportunity" extensions="ONEN_controller_NewOppWizard"> <script > //hack to override JavaScript that is setting focus on Date field function setFocusOnLoad() {} </script> <apex:sectionHeader title="New Opportunity" subtitle="Use this page to create an opportunity and set contact roles"/> <apex:form > <apex:pageBlock title="Contact and Organization"> <apex:actionRegion > <apex:outputPanel > <apex:outputLabel value="Apply Opportunity To" for="oppApplicantSelect"/> <apex:selectRadio id="oppApplicantSelect" value="{!oppApplicant}"> <apex:selectOption itemValue="Contact" itemLabel="Contact"/> <apex:selectOption itemValue="Organization" itemLabel="Organization"/> <apex:actionSupport event="onchange" rerender="orgSection" status="status"/> </apex:selectRadio> <apex:actionStatus startText="applying value...{!oppApplicant}" id="status"/> </apex:outputPanel> </apex:actionRegion> <apex:outputLabel value="Primary Contact" for="contactField"/> <apex:inputField id="contactField" value="{!conactRelationshipDummy.Contact__c}"/> </apex:pageBlock> <apex:pageBlock title="Organization info" id="orgSection" rendered="{!oppApplicant == 'Organization'}"> <apex:outputLabel value="Organization" for="accountField"/> <apex:inputField id="accountField" value="{!opportunity.AccountId}"/> <apex:outputText value="{!oppApplicant}"/> </apex:pageBlock> <apex:pageBlock > <apex:outputLabel value="Record Type" for="oppRecordType"/> <apex:selectList size="1" id="oppRecordType" value="{!oppRecordTypeId}"> <apex:selectOptions value="{!recordTypeNameList}"/> </apex:selectList> <apex:commandButton action="{!step2}" value="Continue"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlock> </apex:form> </apex:page>
Code:
public class ONEN_controller_NewOppWizard { //object to hold opportunity Opportunity opportunity = new Opportunity(); ONEN_RecordTypes OppRecordTypes; public OpportunityContactRole oppContactRole { get {return oppContactRole;} set {oppContactRole = value;} } public ONEN_Relationship_Contact_2_Contact__c conactRelationshipDummy { get {return conactRelationshipDummy;} set {conactRelationshipDummy = value;} } public String oppApplicant { get {return oppApplicant;} set {oppApplicant = value;} } public Id oppRecordTypeId { get {return oppRecordTypeId;} set {oppRecordTypeId = value;} } Contact primaryContact = new Contact(); Account primaryOrg = new Account(); public List<RecordType> recordTypeList { get { return recordTypeList; } set { recordTypeList=value; } } Id contactId; Id accountId; //constructor public ONEN_controller_NewOppWizard (ApexPages.StandardController controller) { this.opportunity = (Opportunity)controller.getRecord(); conactRelationshipDummy = new ONEN_Relationship_Contact_2_Contact__c(); opportunity.AccountId = ApexPages.currentPage().getParameters().get('accountId'); conactRelationshipDummy.Contact__c = ApexPages.currentPage().getParameters().get('contactId'); if(ApexPages.currentPage().getParameters().get('contactId')!=null) { oppApplicant = 'Contact'; } else { oppApplicant = 'Organization'; } ONEN_RecordTypes OppRecordTypes = new ONEN_RecordTypes('Opportunity'); recordTypeList = OppRecordTypes.getRecordTypesForObject(); // system.debug(OppRecordTypes); // system.debug(recordTypeList); List<SelectOption> recordTypeOptions = new List<SelectOption>(); for (RecordType thisRecordType : recordTypeList) { recordTypeOptions.add(new SelectOption(thisRecordType.Id,thisRecordType.Name)); } recordTypeNameList = recordTypeOptions; } public List<SelectOption> recordTypeNameList { get { return recordTypeNameList; } set { recordTypeNameList = value; } } public PageReference step2() { //set name of opp String OppNamePrefix; String oppAccountName; opportunity.RecordTypeId = oppRecordTypeId; if (conactRelationshipDummy.Contact__c!=null) { primaryContact = [select Household_Name__c, FirstName, LastName from Contact where Id=:conactRelationshipDummy.Contact__c]; opportunity.CR_Contact_Id__c = conactRelationshipDummy.Contact__c; } if (opportunity.AccountId!=null) { primaryOrg = [select Name from Account where Id=:opportunity.AccountId]; oppAccountName = primaryOrg.Name; } if (oppApplicant=='Contact') { //get Contact info if (primaryContact.Household_Name__c!=null) { OppNamePrefix = primaryContact.Household_Name__c; } else { OppNamePrefix = primaryContact.FirstName + ' ' + primaryContact.LastName; } opportunity.CR_Contact_Role__c = 'Individual Donor'; opportunity.CR_HHroles__c = true; } else { OppNamePrefix = oppAccountName; opportunity.CR_Contact_Role__c = 'Organizational Donor'; opportunity.CR_HHroles__c = false; } ONEN_RecordTypes OppRecordTypes = new ONEN_RecordTypes('Opportunity'); opportunity.Name = OppNamePrefix + ' ' + system.Today().year() + ' ' + OppRecordTypes.GetOppNamingSuffix(OppRecordTypes.GetRecordTypeName(opportunity.RecordTypeId)); opportunity.StageName = ONEN_Constants.OPP_DEFAULT_STAGE; return Page.newOppWizardStep2; } public PageReference cancel() { PageReference oldPage = new PageReference('/' + conactRelationshipDummy.Contact__c); oldPage.setRedirect(true); return oldPage; } public PageReference save() { insert opportunity; PageReference newOpp = new PageReference('/' + opportunity.id +'/e'); newOpp.setRedirect(true); return newOpp; } }
you may also need an action="{!blahblah}" on selectRadio, so that the page has to call back to apex, blahblah can just return null;
Steve I think your problem is that your trying to rerender something that does not exist on your page. When you first load up your page, your pageBlock is not rendered, so when you try to find the id of the component you're supposed to rerender, it's not there. You might want to try putting an outputPanel around your pageBlock and give the outputPanel the orgSection id, and leave the rendered attribute alone on your pageBlock. That way it will rerender your outputPanel, and ask it to encode all of it's children again.
Make sense?
I created outputPanels that I rerender and had the fields inside that with the rendered= conditional.
thanks!