These are chat archives for ThoughtWorksInc/Binding.scala

19th
Jan 2017
杨博 (Yang Bo)
@Atry
Jan 19 2017 00:52
@vaclavsvejcar https://youtrack.jetbrains.com/issue/SCL-8834 and ThoughtWorksInc/Binding.scala#31
jfilali
@jfilali
Jan 19 2017 07:14

I tried this :

class CustomTag(){
  @BeanProperty var field : String = ""
  override def toString = s"Person: $field"
}

@JSExport
object Foo {
  @fxml def test() = { <CustomTag field="test"/> }
}

[error] java.lang.ClassNotFoundException: sth.pkg.CustomTag
[error] at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[error] at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[error] at java.lang.Class.forName0(Native Method)
[error] at java.lang.Class.forName(Class.java:264)
[error] at com.thoughtworks.binding.fxml$Macros.resolvePropertiesForJavaBean(fxml.scala:928)
[error] @fxml def test() = { <CustomTag field="test"/> }

I tried

class CustomTag(@BeanProperty var field:String){
  override def toString = s"Person: $field"
}

sth.pkg.CustomTag is not a Java Bean nor a type built from JavaFXBuilderFactory
[error] @fxml def test() = { <CustomTag field="test"/> }
[error] ^

I also tried to create a regular java class :

public class CustomTag {
    private String field;
    public CustomTag(){

    }

    public CustomTag(String field){
        this.field=field;
    }

    public String getField() {
        return field;
    }

    public void setField(String field) {
        this.field = field;
    }
}

and get java.lang.ClassNotFoundException:

I also tried to add an import next to it :

  @fxml def test() = {
      import sth.pkg.CustomTag
Do I miss something ? Thanks for the help !
杨博 (Yang Bo)
@Atry
Jan 19 2017 07:17
Ah, currently CustomTag class definition and FXML that uses the CustomTag must not compile together
You can put CustomTag in another project or move FXML to test directory
Sorry I forgot to mention the limitation
jfilali
@jfilali
Jan 19 2017 07:18
no worries, that is fine, let me try. Thank you !
杨博 (Yang Bo)
@Atry
Jan 19 2017 07:20
Could you fire an issue on Github?
jfilali
@jfilali
Jan 19 2017 07:20
sure.
杨博 (Yang Bo)
@Atry
Jan 19 2017 07:21
I think there should be a proper error message instead of ClassNotFoundException
杨博 (Yang Bo)
@Atry
Jan 19 2017 07:29

Note that the following error message is correct

sth.pkg.CustomTag is not a Java Bean nor a type built from JavaFXBuilderFactory

for

class CustomTag(@BeanProperty var field:String){
  override def toString = s"Person: $field"
}

Because a JavaBean must have a nullary constructor.

jfilali
@jfilali
Jan 19 2017 07:31
yes true, I should have remove it from my example. This is not relevant.
I just tried and it work fine when the class is defined in a different project but it has to be a complete different project. It doesn't work in the shared project. I added the comment in the #41
杨博 (Yang Bo)
@Atry
Jan 19 2017 07:37
What does shared project mean?
I guess FXML in src/test/scala can use JavaBeans in src/main/scala
jfilali
@jfilali
Jan 19 2017 07:39
sorry, I was refering to cross compile project jvm - scala-js .
let me correct that.
杨博 (Yang Bo)
@Atry
Jan 19 2017 07:41
Do you mean FXML in jvm/src/main/scala and JavaBeans in shared/src/main/scala?
jfilali
@jfilali
Jan 19 2017 07:41
no a cross project where you define scala code that will compile in both Js and Jvm
杨博 (Yang Bo)
@Atry
Jan 19 2017 07:43
jvm/src/main/scala and shared/src/main/scala are built together at once
jfilali
@jfilali
Jan 19 2017 07:44
yes and you will get a js version too in same time.
jfilali
@jfilali
Jan 19 2017 08:25

Atry , there is still a use case that I think will benefit to anyone using Binding.scala that i'm unable to come up with

I'm trying to define CustomTag like this

class CustomTag(){

  def apply() = <div>something cutom</div>



}

and also try this


class CustomTag() extends Frag{



  @fxml  def render:org.scalajs.dom.Element = <div>Hello World</iv>

}

so I can use it in a dom Binding like this

@dom def Home() ={
    <div><CustomTag></div>
}
At this point I don't know if it is possible to do that.
杨博 (Yang Bo)
@Atry
Jan 19 2017 08:30
That will require the trick mentioned in ThoughtWorksInc/Binding.scala#4