I'm stuck on my rendered argument here - I'm fairly positive i'm pulling values from the record itself and not from the visualforce page. When I change the value (are_you_kp__c) from the record to a "No" - the pageblocksection shoud render, but for some reason it doesn't. Does anybody know why?
I think I need some controller work here - but not sure where to go from here...
<apex:pageBlock title="New Bid" mode="maindetail" tabStyle="Proposal__c">
<apex:messages/>
<apex:actionRegion>
<apex:pageBlockSection columns="2" title="Bid Information" collapsible="false" showHeader="true">
<apex:inputField value="{!rfp.Bid_Amount__c}"/>
<apex:outputField value="{!rfp.Bid_Date__c}"/>
<apex:inputField value="{!rfp.Bid_Deliver_By__c}"/>
<apex:inputField value="{!rfp.Bid_Comments__c}"/>
<apex:pageBlockSectionItem>
<apex:outputLabel value="Are you the Key Appraiser?"/>
<apex:outputPanel>
<apex:inputField value="{!rfp.are_you_kp__c}" required="true">
<apex:actionSupport status="StatusChange" event="onchange" rerender="PageErrors, appraiserInfo"/>
<apex:actionStatus startText="Updating page ..." id="StatusChange"/>
</apex:inputField>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:actionRegion>
<apex:pageBlockSection title="Testing" columns="2" rendered="{!rfp.are_you_kp__c == 'No'}" id="appraiserInfo">
<apex:pageBlockSectionItem>
<apex:outputLabel value="Single Point of Contact" for="spoc"/>
<apex:selectList id="spoc" value="{!rfp.SPOCL__c}" size="1" title="Single Point of Contact Select">
<apex:selectOptions value="{!SPOCS}"></apex:selectOptions>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
Updated - wrapped the to be rendered element in outputPanel with correct id: Still have the problem of toggling my rendered boolean as a result of a change on an inputField - how would I toggle this in the controller? I think i need to evaluate if the inputField value = No, and set the rendered to true by that - i'm not sure how though...
<apex:outputPanel id="appraiserInfo">
<apex:pageBlockSection title="Testing" columns="2" rendered="{!rfp.are_you_kp__c == 'No'}">
<apex:pageBlockSectionItem>
<apex:outputLabel value="Single Point of Contact" for="spoc"/>
<apex:selectList id="spoc" value="{!rfp.SPOCL__c}" size="1" title="Single Point of Contact Select">
<apex:selectOptions value="{!SPOCS}"></apex:selectOptions>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection></apex:outputPanel>
Alright one more attempt - this time it works, but I don't quite get why...only that it does. This is in addition to adding action="{!updateAnswer}" to the actionSupport above (or below, whichever way you see it)
public pageReference updateAnswer(){
if(this.p.are_you_kp__c == 'No')
rfp.are_you_kp__c = 'No';
try{
update rfp;
}
catch (DmlException ex){
ApexPages.addMessages(ex);
return null;
}
return null;
}
Probably relevant controller code
public ProposalExtension(ApexPages.StandardController pCon) {
this.p = (Proposal__c)pCon.getRecord();
}
Wrap the element in an
<apex:outputPanel>
and re-render that, not the element you want to appear. The problem is that the element isn't in the page when it's not rendered, so it's not a working target for re-render.It's something that often catches people out, myself included — I wrote a blog post about it here: http://www.laceysnr.com/2011/10/using-rerender-to-render-one-solution.html
** EDIT **
Didn't spot before that you didn't have an action specified in your
<apex:actionSupport>
tag. You can use that to call the action on the controller. Since the select list is writing to the value you want, you don't actually need to do anything in the code (unless you want to) you could just do this:Hope that helps!