Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HostServices as dependency #26

Open
pacop opened this issue Feb 10, 2017 · 1 comment
Open

HostServices as dependency #26

pacop opened this issue Feb 10, 2017 · 1 comment
Assignees
Labels

Comments

@pacop
Copy link

pacop commented Feb 10, 2017

Hi,
I was trying to share the instance of hostServices with one of the my controllers, but I am getting constantly a nullPointerException

object Main extends JFXApp {

  val resource = getClass.getResource("/Views/main.fxml")

  val i18n = new PropertyResourceBundle(getClass.getResource("/i18n/en.properties").openStream)

  val my: HostServices = hostServices
  
  val loader = new FXMLLoader(resource, new DependenciesByType(Map(
                                  typeOf[HostServices] -> my))) {
    setResources(i18n)
  }

  val root = loader.load[javafx.scene.Parent]
  val controller = loader.getController[UnitController]

  stage = new PrimaryStage() {
    title = "Test"
    scene = new Scene(root)
  }

In MainController:

@sfxml
class MainController(val hostServices: HostServices) extends UnitController {
    println("HostServices: " + (hostServices.delegate== null))
  }
}

Although in MainController hostServices is NOT null, hostServices.delegate is null. Any idea?

@vigoo vigoo added the question label Feb 10, 2017
@vigoo vigoo self-assigned this Feb 10, 2017
@pacop
Copy link
Author

pacop commented Feb 10, 2017

If I create the following hack, and it works. BTW, pretty dirty solution.

class P(var my: HostServices = null) {}
val loader = new FXMLLoader(resource, new DependenciesByType(Map(
                                  typeOf[P] -> new P(hostServices)))) {
    setResources(i18n)
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants