1

I have a multiselect picklist called transport. I need to render two other picklists depending on the value selected in multislelect picklist 'Transport'.

I am using following code to render those two picklists :

<apex:outputPanel rendered="{!opp.Optional_Transport__c.contains('Train')}" >

But above line through following error :

Unknown function opp.Optional_Addenda__c.contains. Check spelling.

I have also tried using this way but it gives another error :

<apex:outputPanel rendered="{!IF(CONTAINS({!opp.Optional_Transport__c}, "Train "),True, False)}" >

Error "Element type "apex:outputPanel" must be followed by either attribute specifications, ">" or "/>"."

Can someone please help me if you know what to do for Multiselect list in this case?

3

Replace :

<apex:outputPanel rendered="{!IF(CONTAINS({!opp.Optional_Transport__c}, "Train "),True, False)}" >

by :

<apex:outputPanel rendered="{!CONTAINS(opp.Optional_Transport__c, 'Train ')}" >...<apex:outputpanel>

CONTAINS method already returns a Boolean value.

You don't need to add several {!...} in rendered

And you need to close your <outputPanel> tag.

  • 1
    Notice the trailing space after Train... – Adrian Larson Feb 4 '16 at 15:12
  • Yes, I noticed that, but maybe it's a desired thing... – SF_user Feb 4 '16 at 15:16
  • ya I have applied the above mentioned snippet it is not giving me error now, however that panel is rendering no matter what is selected in multiselect picklist, Or even not selected anything – Ricky Feb 4 '16 at 15:28
  • on the controlling multi select list I use <apex:actionSupport event="onchange" reRender="Train" status="wait" /> – Ricky Feb 4 '16 at 15:30
2

You can't use Apex methods in Visualforce markup. You are also using unescaped double quotes in your second approach. Change it to:

<apex:outputPanel rendered="{!CONTAINS(opp.Optional_Transport__c, 'Train')}" />

Note that IF(condition, true, false) is always functionally equivalent to just condition.

  • 3
    I think it should be like {!CONTAINS(opp.Optional_Transport__c, 'Train')}. Let me know if I am wrong? – Ratan Paul Feb 4 '16 at 15:20
  • 1
    @Ratan Yep, sorry, didn't notice it duplicated. Copy pasta ftw. – Adrian Larson Feb 4 '16 at 15:24
  • @AdrianLarson yes you were right, Your code snippet is not giving me error no more. However fields are rendering no matter what is selected on multi select list, or even if it is blank this panel still loads. I am using following tab to render that panel <apex:actionSupport event="onchange" reRender="Train" status="wait" /> – Ricky Feb 4 '16 at 15:32
  • @Ricky That's outside the scope of your question. You should probably create a separate question with more complete context to address it. – Adrian Larson Feb 4 '16 at 15:44
  • @AdrianLarson it is not different question as that action support is working good on its end only this field panel is not rendering according to the condition. Which i think it should be – Ricky Feb 4 '16 at 16:14

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.