0

I need to render visualforce tabs in a tabpanel based on whether a multiselect picklist field is selected. But not getting the tab to show/hide using the following (Revised) approach:

<apex:page standardStylesheets="true" standardController="Account_Summary__c" readOnly="false"  showHeader="true"  >
<apex:stylesheet value="{!URLFOR($Resource.pdfcssresource, 'CREresource_CRE.css')}"/>
<apex:form id="form1">
<apex:pageBlock id="block1"  >
<apex:actionRegion > 

<apex:pageBlockSection columns="1" id="section1" title="General Information" showHeader="true" >

    <apex:inputField value="{!Account_Summary__c.Lines_of_Business__c}" style="color:blue;" >
        <apex:actionSupport event="onchange" reRender="tab1a,tab1b,tab1c,theTabPanel" /> 
        </apex:inputField>          
    <apex:inputField value="{!Account_Summary__c.Other_Line_of_Business__c}"  style="color:blue;" rendered="{!CONTAINS(Account_Summary__c.Lines_of_Business__c,'Other')}" />'

</apex:pageBlockSection>

<apex:actionRegion immediate="true" >    
<apex:outputPanel >
<b><apex:outputText style="font-style:bold;color:blue" value="Line of Business Analysis" /></b>

<apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel">
<apex:tab label="TEST1" name="tab1a" id="tab1a" rendered="{!CONTAINS(Account_Summary__c.Lines_of_Business__c,'Workers Compensation')}" > </apex:tab>
<apex:tab label="TEST2" name="tab1b" id="tab1b" rendered="{INCLUDES(Account_Summary__c.Lines_of_Business__c,'Workers Compensation')}" > </apex:tab>
<apex:tab label="TEST3" name="tab1c" id="tab1c" rendered="{!IF(CONTAINS(Account_Summary__c.Lines_of_Business__c,'Workers Compensation'),"true","false")}"  > </apex:tab>

</apex:tabPanel>
</apex:outputPanel>
</apex:actionRegion>


</apex:actionRegion>
</apex:pageBlock>
</apex:form>
</apex:page>
3
  • It should be INCLUDES, not CONTAINS.
    – Adrian Larson
    Feb 16, 2017 at 3:12
  • Function INCLUDES may not be used in this type of formula
    – rickmac
    Feb 16, 2017 at 17:35
  • !INCLUDES results in error. INCLUDES does not fix rendering issue. Have used!CONTAINS with other multi-select fields rendering . For some reason not on this one.
    – rickmac
    Feb 16, 2017 at 17:59

1 Answer 1

1

You should use a CASE formula function. Please find the below example where Country__c is a picklist which contains different Country names.

<!-- Page: -->
<apex:page standardController="Book__c" id="thePage">
    <apex:form>
        <apex:inputField value="{!Book__c.Country__c}">
            <apex:actionSupport event="onchange" reRender="theTabPanel" />
        </apex:inputField>
    </apex:form>
    <apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel">
        <apex:tab label="One" name="name1" id="tabOne" rendered="{!CASE(Book__c.Country__c,"USA", "true","false")}">content for tab one</apex:tab>
        <apex:tab label="Two" name="name2" id="tabTwo">content for tab two</apex:tab>
    </apex:tabPanel>
</apex:page>

In your code the rendered attribute should be changed to this.

rendered="{!CASE(Account_Summary__c.Lines_of_Business__c,"Workers Compensation", "true","false")}"

If you using multi-select picklist you can use the CONTAINS function. In the below example multipicklist__c is a multi-select picklist which contains A,B,C,D E.

<!-- Page: -->
<apex:page standardController="Book__c" id="thePage">
    <apex:form>
        <apex:inputField value="{!Book__c.multipicklist__c}">
            <apex:actionSupport event="onchange" reRender="theTabPanel" />
        </apex:inputField>        
    </apex:form>
    <apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel">
        <apex:tab label="One" name="name1" id="tabOne">content for tab one</apex:tab>
        <apex:tab label="Two" name="name2" id="tabTwo" rendered="{!IF(CONTAINS(Book__c.multipicklist__c,"A") && CONTAINS(Book__c.multipicklist__c,"B"),"true","false")}" >content for tab two</apex:tab>
    </apex:tabPanel>
</apex:page>

Update code according to updated question.

<!-- Page: -->
<apex:page standardController="Book__c" id="thePage">
    <apex:form >
        <apex:pageBlock id="block1"  >
            <apex:actionRegion >
                <apex:pageBlockSection columns="1" id="section1" title="General Information" showHeader="true" >
                    <apex:inputField value="{!Book__c.multipicklist__c}">
                        <apex:actionSupport event="onchange" reRender="outputpanel" />
                    </apex:inputField> 
                </apex:pageBlockSection>
                <apex:actionRegion immediate="true" >
                    <apex:outputPanel id="outputpanel"  >
                        <apex:tabPanel  switchType="client" selectedTab="name2" rendered="{!CASE(Book__c.multipicklist__c,'A', 'true','false')}"  id="theTabPanel">
                            <apex:tab label="One" name="name1" id="tabOne">content for tab one</apex:tab>
                            <apex:tab label="Two" name="name2" id="tabTwo">content for tab two</apex:tab> 
                        </apex:tabPanel>
                    </apex:outputPanel>
                </apex:actionRegion>
            </apex:actionRegion>
        </apex:pageBlock>
    </apex:form>
</apex:page>
8
  • Still not working. Added revised code above in original post.
    – rickmac
    Feb 16, 2017 at 19:50
  • The above example is a working example. Can you please post your entire page structure containing all major elements, like <apex:page .. <apex:form ... <apex:actionRegion .. <apex:inputfield ... <apex:actionsupport. You may show only these major dependent elements skipping rest of the code.
    – Saroj Bera
    Feb 17, 2017 at 3:53
  • I added a short version of the complete page. Still, rendering is not working. The tab 'TEST1' shows with nothing in the pick. Choose any value and tab TEST1 dissapears. TEST2 and TEST3 tabs never show.
    – rickmac
    Feb 24, 2017 at 17:19
  • What is Lines_of_Business__c field, is it multi select or single select? I tried your code structure and it is working for me. Can you please explain a little bit more on the conditions for tab hide and show.
    – Saroj Bera
    Feb 25, 2017 at 3:39
  • Multi select pick list . Do all three test tabs render or just one of them.
    – rickmac
    Feb 25, 2017 at 3:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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