When I do this I get an error ....">

Use String.contains in Apex page

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


When I do this I get an error ...

Error: Unknown WidgetType.contains function. Spellchecking

... even if WidgetType returns a string!

This will allow me to do it though ...

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

Here is a property in the controller ...

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



source to share

2 answers

Review the CONTAINS

function documentation (box below).


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

The following example checks the content of the custom text field 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 make sure the compare_text value has the correct capital letter.


CONTAINS(text, compare_text)

and replace the text with the text that contains the compare_text value.

In your case, you will 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.



All Articles