<apex:outputField rendered="{!(WidgetType.contains('mywidget1'))}" />

When I do this I get an error...

Error: Unknown function WidgetType.contains. Check spelling

... even though the WidgetType returns a String!

It will let me do this though...

rendered="{!(WidgetType == 'mywidget1')}"

Here is the property in the controller...

public String getWidgetType() {return Settings.getWidgetType();}
2

Best Answer


Check out the CONTAINS function documentation (pasted below).


Description

Compares two arguments of text and returns TRUE if the first argument contains the second argument. If not, returns FALSE.

The following example checks the content of a custom text field named Product_Type and returns “Parts” for any product with the word “part” in it. Otherwise, it returns “Service.”{!IF(contains(opportunity.Product_Type__c, "part"), "Parts", "Service")}

This function is case sensitive so be sure your compare_text value has the correct capitalization.

Use

CONTAINS(text, compare_text) and replace text with the text that contains the value of compare_text.


In your case, you would need to use it like this:

<apex:outputField rendered="{!(CONTAINS(WidgetType,'mywidget1'))}" />

<apex:outputPanel rendered="{!(contains('long_string','short_string_to_check'))}" />

This works for me.