1

I'm trying to compare the value of a property to a String using isEqualsTo. This value always returns true, regardless of the string I'm comparing the property to. I have a model that has a messageType, this message type is a string and it could be CLOSED or WARNING.

I have the following model:

class MessageModel {
    @FXObservable String messageType
}

This is my view

MessageModel model

      String CLOSED = 'CLOSED'
        String WARNING = 'WARNING'

    if (model.messageTypeProperty().isEqualTo(CLOSED)) {
                image.setImage(new Image("/com/pppp/ddd/img/messageLock.png"))
            } else if (model.messageTypeProperty().isEqualTo(WARNING)) {
                image.setImage(new Image("/com/pppp/ddd/img/messageWarning.png"))
            }

This doesn't work, it always returns true on the first IF.

Any help would be appreciated!

Syrup72
  • 116
  • 1
  • 12
  • 2
    I'm not familiar with Groovy, so maybe this isn't a problem, but assuming you're using [`StringExpression#isEqualTo(String)`](https://openjfx.io/javadoc/12/javafx.base/javafx/beans/binding/StringExpression.html#isEqualTo(java.lang.String)) that method returns a `BooleanBinding`. This means you have `if ()`; is this intentional? – Slaw Sep 02 '19 at 19:24
  • I'm not completely sure it's alright that way, I fairly new to Javafx. What I'm really trying to do is compare the value that I have in the in the model which is a String to the String value of 'CLOSED' or 'WARNING' – Syrup72 Sep 02 '19 at 19:31
  • 3
    You could try `messageTypeProperty().get().equals(CLOSED)`. – Slaw Sep 02 '19 at 19:37
  • 2
    In java you'd use `model.getMessageType().equals(CLOSED)`... – fabian Sep 02 '19 at 19:37
  • 1
    @Slaw thanks for pointing me in the right direction, I was using it in the wrong place, now it works with what you said. If you want you can post it as an answer and I'll take it! – Syrup72 Sep 03 '19 at 12:26

0 Answers0