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.

I am trying to view a section based on a condition ... but it seems that the Rendered statement always return false, I'm not sure where I went wrong! but could someone help me?

here is my code

     <!--the buttons block  -->
     <apex:pageBlockButtons >
       <apex:commandButton value="Save" action="{!save}"/>
       <apex:commandButton value="Cancel" action="{!cancel}"/>
     </apex:pageBlockButtons>
     <!--end of buttons block -->  

 <apex:actionRegion >
   <!--Section 1 -->   
   <apex:pageBlockSection title="Basic Information" columns="2">


             <apex:inputField value="{!Client_Session_Record__c.name}"/>

            <!-- the condition -->
             <apex:pageBlockSectionItem >              
                 <apex:outputLabel value="Session Type"/> 
                 <apex:outputPanel > 
                     <apex:inputField value=" {!Client_Session_Record__c.Session_Type__c}">
                          <apex:actionSupport event="onchange"
                                       reRender="thePageBlock"
                                       status="status"/>
                     </apex:inputField>
                     <apex:actionStatus startText="checking..."
                                    id="status"/>
                 </apex:outputPanel> 
             </apex:pageBlockSectionItem>
             <!-- end of condition -->
   </apex:pageBlockSection>

<!--Section 1 -->     

 </apex:actionRegion>

 <!--Section 2 -->  
 <apex:outputPanel > 
 <apex:pageBlockSection title="Initial Assessment" id="Section2"
       columns="2"  collapsible="false"
       Rendered="{if(!Client_Session_Record__c.Session_Type__c == 'Initial Assessment',true,false)}"  > 


 </apex:pageBlockSection>
 </apex:outputPanel >    <!--Section 2 -->  
   <!--Section 3 -->  
 <apex:pageBlockSection title="Provision" id="Section3"
       columns="2"  
         > 
 </apex:pageBlockSection>            </apex:pageBlock>  </apex:form> </apex:page>

one more question, do rich text fields not work with Rendered sections ? sometimes i get this error that rich text fields are not supported with Rendered!

share|improve this question
    
Can you post code from your controller? Perhaps there's something always setting it to false. If you really get stuck or if the logic starts to get complex, you might want to try abstracting the render logic in to method in the controller, e.g., public Boolean getRednerPageBlock() { //complex logic that ends with a Boolean value returned. } and then just have the rendered condition as <pageBlock rendered="{!rerenderPageBlock}'>. –  Peter Knolle Dec 26 '12 at 19:59
    
thanks it did work when i used a public class! :) –  maha Dec 27 '12 at 5:00
add comment

3 Answers 3

I'm guessing you are using a Standard Controller

Heres a simplistic reduced form of your problem, which works okay - here the second pageBlockSection is rendered when the Account Type is 'Prospect'

A few observations, while I see you are trying to reRender the pageBlock, i don't see it as part of your markup. You will need to rerender the containing element to render a component that wasn't originally rendered when the page loaded, in this case your second pageBlockSection.

Also for your rendered expression - it is enough to write rendered = "{!Client_Session_Record__c.Session_Type__c == 'Initial Assessment'}"

<apex:page standardController="Account">

<apex:form>
<apex:pageBlock id="thePageBlock">

<apex:actionRegion>
<apex:pageBlockSection id="pbs1" title="Basic Information" columns="2"> 

    <apex:inputField value=" {!Account.Type}">
           <apex:actionSupport event="onchange" reRender="thePageBlock" status="status"/>
    </apex:inputField>
            <apex:actionStatus startText="checking..." id="status"/>

</apex:pageBlockSection>
</apex:actionRegion>

<apex:pageBlockSection title="Initial Assessment" id="Section2"
       columns="2"  collapsible="false" rendered="{!Account.Type=='Prospect'}"> 

<apex:outputField value="{!Account.Name}"/>

</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
share|improve this answer
    
thanks all for answering my question I did try using rendered = "{!Client_Session_Record__c.Session_Type__c == 'Initial Assessment'}" and it didn't work, that's why I went to the if statement but still didn't work... it's like the rendered condition is always false for some reason –  maha Dec 26 '12 at 12:10
add comment
<apex:pageBlockSection title="Initial Assessment" id="Section2"
   columns="2"  collapsible="false"
   Rendered="{!IF(Client_Session_Record__c.Session_Type__c =='Initial Assessment','true','false')}"> 
</apex:pageBlockSection>

Ensure You have Getter Setter for boolean and once its set its returned on the Page .May be reRender of the Pannel can help.

Answering your Second question there is some hack on this blog .Have a look at this

http://www.laceysnr.com/2012/10/rerender-rich-text-field-hack-city.html

share|improve this answer
    
thanks all for answering my question –  maha Dec 26 '12 at 12:07
add comment
<apex:page standardController="category_wise__c" extensions="rendering">
 <apex:form >
 <apex:pageBlock id="thePageblock">
 <apex:pageBlockSection columns="1">
<apex:actionSupport rendered="true" immediate="true" event="onchange" reRender="thePageblock">
 <apex:inputField value="{!category_wise__c.category__c}"/>
 <apex:actionStatus >
   <apex:inputField value="{!category_wise__c.IPD_Name__c}" rendered="{!category_wise__c.category__c=='IPD'}"/>
 <apex:inputField value="{!category_wise__c.IPD_Disease__c}" rendered="{!category_wise__c.category__c=='IPD'}"/>
 <apex:inputField value="{!category_wise__c.IPD_Details__c}" rendered="{!category_wise__c.category__c=='IPD'}"/>
 <apex:inputField value="{!category_wise__c.IPD_Phone_No__c}" rendered="{!category_wise__c.category__c=='IPD'}"/>
 <apex:inputField value="{!category_wise__c.OPD_Name__c}" rendered="{!category_wise__c.category__c=='OPD'}"/>
 <apex:inputField value="{!category_wise__c.OPD_Disease__c}" rendered="{!category_wise__c.category__c=='OPD'}"/>
 <apex:inputField value="{!category_wise__c.OPD_Details__c}" rendered="{!category_wise__c.category__c=='OPD'}"/>
 <apex:inputField value="{!category_wise__c.OPD_Phone_No__c}" rendered="{!category_wise__c.category__c=='OPD'}"/>
 <apex:commandButton value="Save" action="{!save}" rendered="{(!category_wise__c.category__c=='OPD') || (!category_wise__c.category__c=='OPD')}"/>
 </apex:actionStatus>
 </apex:actionSupport>
 </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
</apex:page>

its the right way to use rendered

share|improve this answer
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.