Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Here is my code the idea is when the user picks a value from the drop down i want to render siblings. I looked at http://wiki.developerforce.com/page/Visualforce_DynamicEditPage but i can't get mine to render the conditional part at the bootom (the 2nd close date)

Any ideas how to accomplish this? I don't want to nest them in a pageblockSection

        <apex:page standardController="Opportunity" sidebar="false">
        <apex:sectionHeader title="Edit Opportunity" subtitle="{!opportunity.name}"/>
        <apex:form >
            <apex:pageBlock title="Edit Opportunity" id="thePageBlock" mode="edit">
                <apex:pageMessages />
                <apex:pageBlockButtons >
                    <apex:commandButton value="Save" action="{!save}"/>
                    <apex:commandButton value="Cancel" action="{!cancel}"/>                
                </apex:pageBlockButtons>
                <apex:actionRegion >
                    <apex:pageBlockSection title="Basic Information" columns="1">
                        <apex:inputField value="{!opportunity.name}"/>
                        <apex:pageBlockSectionItem >
                            <apex:outputLabel value="Stage"/>
                            <apex:outputPanel >
                                <apex:inputField value="{!opportunity.stageName}">
                                    <apex:actionSupport event="onchange" rerender="test"
                                                        status="status" />
                                </apex:inputField>
                                <apex:actionStatus startText="applying value..." id="status"/>
                            </apex:outputPanel>
                        </apex:pageBlockSectionItem>
                        <apex:inputField value="{!opportunity.amount}"/>
                        <apex:inputField value="{!opportunity.closedate}"/>
                    </apex:pageBlockSection>
                </apex:actionRegion>
                <apex:pageBlockSection title="Closed Lost Information" columns="1"
                                       rendered="{!opportunity.stageName == 'Closed Lost'}" id="test">
                    <apex:inputField value="{!opportunity.CloseDate}"  required="true"/>

                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form>
    </apex:page>
share|improve this question
    
You should add an ID to the pageMessages tag and rerender that as well. I suspect that you aren't seeing an error which is occurring on the page. –  Mark Pond Jan 18 '13 at 21:10
add comment

3 Answers 3

up vote 1 down vote accepted

The outputPanel with id=test does not render if at load the Stage is not Closed Lost. I don't believe it is possible to rerender an element (pageBlockSection in this case) which hasn't rendered when the page loaded. You would need to reRender a parent such as the pageBlock.

Here is a great blog post explaining this behaviour.

share|improve this answer
add comment

change your actionsupport as below as your action region encompasses other required fields which i believe are not getting validated:

<apex:actionSupport event="onchange" rerender="test, thePageBlock"
                                                        status="status" />

but it is better if you move the actionregion to include only the stage field (source) as below:

 <apex:pageBlockSection title="Basic Information" columns="1">
                        <apex:inputField value="{!opportunity.name}"/>
                        <apex:PageBlockSectionItem >
                         <apex:outputLabel value="Stage"/>
                         <apex:actionRegion >
                          <apex:inputField value="{!Opportunity.StageName}">
                          <apex:actionSupport event="onchange" reRender="test" />
                          </apex:inputField>
                         </apex:actionRegion>
                      </apex:PageBlockSectionItem>
                        <apex:inputField value="{!opportunity.amount}"/>
                        <apex:inputField value="{!opportunity.closedate}"/>
                    </apex:pageBlockSection>

                <apex:outputPanel id="test">
                <apex:pageBlockSection title="Closed Lost Information" columns="1"
                                       rendered="{!opportunity.stageName == 'Closed Lost'}">
                    <apex:inputField value="{!opportunity.CloseDate}"  required="true"/>

                </apex:pageBlockSection>
                </apex:outputPanel>
share|improve this answer
add comment

Here is the corrected code for you.

<apex:page standardController="Opportunity" sidebar="false">
<apex:sectionHeader title="Edit Opportunity" subtitle="{!Opportunity.Name}"/>
<apex:form >
<apex:pageBlock title="Edit Opportunity" id="thePageBlock" mode="edit">
<apex:pageMessages />
<apex:pageBlockButtons >
</apex:pageBlockButtons>
  <apex:actionRegion >
  <apex:pageBlockSection title="Basic Information" columns="1">
      <apex:inputField value="{!Opportunity.Name}"/>
      <apex:pageBlockSectionItem >
         <apex:outputLabel value="Stage"/>
         <apex:outputPanel >
         <apex:inputField value="{!Opportunity.StageName}">
         <apex:actionSupport event="onchange" rerender="thePageBlock" status="status" />
         </apex:inputField>
         <apex:actionStatus startText="applying value..." id="status"/>
         </apex:outputPanel>
      </apex:pageBlockSectionItem> 
   <apex:inputField value="{!Opportunity.Amount}"/>
   <apex:inputField value="{!Opportunity.CloseDate}"/>
   </apex:pageBlockSection>
   </apex:actionRegion>
   <apex:pageBlockSection title="Closed Lost Information" columns="1" rendered="{!opportunity.stageName == 'Closed Lost'}">
      <apex:inputField value="{!Opportunity.CloseDate}" required="true"/>
   </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
share|improve this answer
    
Anil, welcome to Salesforce StackExchange. I've edited your post to make your code visible. When posting code, either paste it in as pre-formatted text or use the spacebar to indent each line at least 4 spaces. Otherwise, any code you post won't be visible to readers. You'll see your reply below when composing your post. You can also use an accent (below the tilde key) to surround code so that it appears correctly when posting it in-line with a reply. Not to worry, I had the same problem when I first came here too! :) –  crmprogdev Jul 6 '13 at 16:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.