You need to sign in to do that
Don't have an account?
Dynamic Layouts on Standard Controller
I have been working with visualforce pages for a few weeks now and I getting the hang of it. I was able to follow the dynamic edit layout fairly easily. Now i am wondering if you can have dynamic sections of your page that function off more than one parameter. Example
I want to show a certain pageblocksection when the Stage is set to Closed and Type of Opportunity = Retail. So basically when two different picklist values match.
Is this possible? I have been researching and trying for a while now to get it working but just banging my head against the wall. Any help would be much appreciated.
I think your problem is that the value for the rendered attribute is not an expression:
<apex:pageBlockSection title="Deal Information" columns="1" rendered="{Opportunity.StageName == 'Closed Lost' && Opportunity.Type == 'New Business'}">
Try this:
<apex:pageBlockSection title="Deal Information" columns="1" rendered="{!Opportunity.StageName == 'Closed Lost' && Opportunity.Type == 'New Business'}">
Notice the missing '!' after the "{" in your code.
All Answers
From what I can tell, yes this is possible. It sounds similar to the concept behind this article which might help you:
http://wiki.developerforce.com/index.php/Visualforce_DynamicEditPage
Yes, definitely you can do this.
I did a lot of such conditional rendering in my VF page.
eg, hide those blank fields on the page, so
<apex:outputField value="{}" rendered="{!not(isnull(field__c))}" />
Render a tab on the tabbed view:
<apex:tab label="Approval History" name="Approval History" id="tabapprovalhis" rendered="{!$Profile.Id='00xxxx'||$Profile.Id='00exxxx'}" > <apex:relatedList subject="{!opportunity}" list="ProcessSteps" /> </apex:tab>
Right, I guess what you are looking for is the example of the expression that combines two fields then.
So in the Dynamic_EditPage example referenced above the following component/expression would need to be changed from its current values:
<apex:pageBlockSection title="Closed Lost Information" columns="1" rendered="{!opportunity.stageName == 'Closed Lost'}">
<apex:inputField value="{!opportunity.competitor__c}" required="true"/>
<apex:inputField value="{!opportunity.Reason_Lost__c}"/>
</apex:pageBlockSection>
To this:
<apex:pageBlockSection title="Closed Lost Information" columns="1" rendered="{!AND(opportunity.stageName == 'Closed Lost',opportunity.amount == 200)}">
<apex:inputField value="{!opportunity.competitor__c}" required="true"/>
<apex:inputField value="{!opportunity.Reason_Lost__c}"/>
</apex:pageBlockSection>
Or if you prefer the more traditional "and" operator:
<apex:pageBlockSection title="Closed Lost Information" columns="1" rendered="{!opportunity.stageName == 'Closed Lost' && opportunity.amount == 200}">
<apex:inputField value="{!opportunity.competitor__c}" required="true"/>
<apex:inputField value="{!opportunity.Reason_Lost__c}"/>
</apex:pageBlockSection>
Apologies for any compile errors, I didn't test the above but you should get the idea.
Can you paste your page and controller - just the portions of each that exhibit the failing issue? If you can remove custom field/object references that will make it easier for others (like me) to test.
Thanks,
Hi, sorry my previous reply was ir-relevant.
I think you need an id tag so you can re-render it in your edit page:
<apex:actionRegion >
<apex:panelGrid columns="6" columnClasses="left,right" width="100%" border="1" >
<apex:outputlabel value="Standard Payment Terms?" />
<apex:outputPanel >
<apex:inputField value="{!LOA_Approval__c.Standard_payment_terms__c}" >
<apex:actionSupport event="onchange" rerender="payment"
status="status"/>
</apex:inputField>
<apex:actionStatus startText="applying value..." id="status"/>
</apex:outputPanel>
........................... removed.....................>
</apex:panelGrid>
</apex:actionRegion>
<apex:pageBlockSection id="payment" columns="1" >
<apex:panelGrid columns="5" id="stdterm" columnClasses="left,right" width="100%" border="1" rendered="{!LOA_Approval__c.Standard_payment_terms__c='Yes'}" >
<apex:outputText value="Item" style="font-weight:bold" />
<apex:outputText value="% payment on PO" style="font-weight:bold" />
<apex:outputText value="% payment on Delivery" style="font-weight:bold" />
<apex:outputText value="% payment on Solution Integration" style="font-weight:bold" />
<apex:outputText value="% payment on Product Acceptance" style="font-weight:bold" />
<apex:outputText value="SW" style="font-weight:bold" />
<apex:inputField value="{!LOA_Approval__c.payment_on_PO_sw__c}" />
<apex:inputField value="{!LOA_Approval__c.payment_on_Delivery_SW__c}" />
<apex:inputField value="{!LOA_Approval__c.payment_on_Installation_Complete_sw__c}" />
<apex:inputField value="{!LOA_Approval__c.payment_on_Product_Acceptance_sw__c}" />
..............................removed ....................
</apex:panelGrid>
<apex:panelGrid columns="2" columnClasses="left,right" width="100%" border="1" rendered="{!LOA_Approval__c.Standard_payment_terms__c='No'}" >
<apex:outputText value="Non Standard Payment Terms" style="font-weight:bold" />
<apex:inputField value="{!LOA_Approval__c.Non_standard_payment_terms__c}" style="width: 600px" required="true" />
</apex:panelGrid>
</apex:pageBlockSection>
I just tested in my sandbox on two conditions and it worked:
<apex:panelGrid columns="5" id="stdterm" columnClasses="left,right" width="100%" border="1" rendered="{!LOA_Approval__c.Standard_payment_terms__c =='Yes' && !LOA_Approval__c.sw_price__c>0 }" >
Sorry it took a little time to build a decent test case with standard fields and the standard opportunity controller. Thanks for all your help. The below doesn't work. The actions are causing the page to be rerendered but the pageblock section just doesn't show up.
<apex:page standardController="Opportunity"> <apex:sectionHeader title="Balanced Deal Worksheet" subtitle="{!Opportunity.Name}"/> <apex:form > <apex:pageBlock title="Balanced Deal Worksheet" id="thePageBlock" mode="detail"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!Save}" rendered="{!Opportunity.StageName == 'Balanced Deal'}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:actionRegion > <apex:pageBlockSection title="Basic Information" columns="1"> <apex:outputField value="{!Opportunity.AccountID}"/> <apex:outputField value="{!Opportunity.Name}"/> <apex:outputField value="{!Opportunity.OwnerID}"/> <apex:inputField value="{!Opportunity.StageName}"> <apex:actionSupport event="onchange" rerender="thePageBlock" status="status"/> </apex:inputField> <apex:actionStatus startText="applying value..." id="status"/> <apex:inputField value="{!Opportunity.Type}"> <apex:actionSupport event="onchange" rerender="thePageBlock" status="status"/> </apex:inputField> </apex:pageBlockSection> <apex:pageBlockSection title="Deal Information" columns="1" rendered="{Opportunity.StageName == 'Closed Lost' && Opportunity.Type == 'New Business'}"> <apex:inputField value="{!Opportunity.Description}"/> </apex:pageBlockSection> </apex:actionRegion> </apex:pageBlock> </apex:form> </apex:page>
I think you dont want to re-render the whole pageblock, because when it is rendered, whatever changes made to the stage field is lost, and the pageblocksection cannot be rendered.
so you may want to just re-render the pageblocksection only. take a look @ my sample code.
I think your problem is that the value for the rendered attribute is not an expression:
<apex:pageBlockSection title="Deal Information" columns="1" rendered="{Opportunity.StageName == 'Closed Lost' && Opportunity.Type == 'New Business'}">
Try this:
<apex:pageBlockSection title="Deal Information" columns="1" rendered="{!Opportunity.StageName == 'Closed Lost' && Opportunity.Type == 'New Business'}">
Notice the missing '!' after the "{" in your code.