"FormatException in property ... " error despite valid Expression Binding syntax

Viewed 54

I would like to display a sap.m.Button in case the value of two model properties are equal. It that possible via expression binding.

Bindings:

  • {user-management>/alias}
    • value: "TESTUSER"
  • {recipe-service>Author/alias}
    • value: "TESTUSER"

My attempts:

<Button xmlns="sap.m" visible="{= ${user-management>/alias} === ${recipe-service>Author/alias}}" />
<!-- or: -->
<Button xmlns="sap.m" visible="{= ${user-management>/alias} === ${recipe-service>Author/alias} ? true : false}"/>

The above attempts are not working resulting with the following console error:

FormatException in property 'visible' of 'Element sap.m.Button#__button1': TESTUSER is not a valid boolean value Hint: single properties referenced in composite bindings and within binding expressions are automatically converted into the type of the bound control property, unless a different 'targetType' is specified. targetType:'any' may avoid the conversion and lead to the expected behavior.

I am not aware of using targetType for expression binding.

1 Answers

You must be using an OData V4 service. In that case, replace $ with % within the expression binding where the V4 OData model value is embedded but causes the above error.

Assuming the latter "recipe-service" model is sap.ui.model.odata.v4.ODataModel:

<Button xmlns="sap.m" visible="{= ${user-management>/alias} === %{recipe-service>Author/alias}}" />

See also the information about the automatic type determination in topics Changes Compared to OData V2 Model and Type Determination.

Related