I have a problem with JSTL and Kotlin interop.
I have a this particular kotlin class with 2 kotlin Boolean fields.
class Foo {
var isBar1 : Boolean = false
var isBar2 : Boolean = false
constructor()
constructor(isBar1: Boolean, isBar2: Boolean) {
this.isBar1 = isBar1
this.isBar2 = isBar2
}
}
I have to acces these two fields from a jsp which i'm doing in the following way:
<c:choose>
<c:when test="${foo.isBar1== true}">
<p>Print something</p>
</c:when>
<c:when test="${foo.isBar1== false}">
<p>Print something else</p>
</c:when>
</c:choose>
And the exact same for isBar2
The problem is, when I run this piece of code I ran into
java.lang.NoSuchMethodError: packagedeclaration.setBar1(Ljava/lang/Boolean;)V
If i try to write the following functions:
fun getBar1(): Boolean {
return this.isBar1
}
fun setBar1(isBar1: Boolean): Any {
this.isBar1= isActive
return Any()
}
fun getBar2(): Boolean {
return this.isBar2
}
fun setBar2(isBar2: Boolean): Any {
this.isBar2= isBar2
return Any()
}
It will take me to "javax.el.PropertyNotFoundException: Property [isBar2] not found on type [packagedeclaration.foo]"
I've tried to set fields as private but it did not help. Java boolean as parameter seems impossible to pass because IntelliJ constantly bombing me with different errors.
Here's my thoughts: JSTL tries to access java getters/setters with java boolean parameter and return type. Jstl looking for methods named with java naming conventions, so getBar1 and setBar1 but kotlin generates isBar1 and setBar1
Java - Kotlin interop for boolean is Boolean according to this kotlin reference page: Kotlin- Java interop reference
Do you have any idea how to get rid of this problem?