Hello,
until now I am searching for a way to pass an argument to a view. I read all the guides I could find but none of them covered my problem.
Here is my code:
package parts.gui.views
class Setup : View() {
override val root : VBox by fxml()
//Do stuff
init{
//start Button
start.setOnAction {
//Open Connection
val req = Requester()
/*
reg.send(Order(bla......))
*/
//change view and pass socket
replaceWith<Overview>() }
}
}
As you can see, I create the view via fxml and configure it. But then I want to open a socket, send the inital information which I gathered with this view. Then I want to pass the socket to the next view for further interaction with the server.
Anything I have seen so far is about binding things together but I don麓t see how that will work for me in this case.
You can find more information about passing parameters and viewmodel/scopes (preferred way) here:
After running several rounds around the block, I found the solution. Pretty simple but it works as intended. I will post parts of it here, you can keep it as an example if you want.
class Setup : View() {
override val root : VBox by fxml()
/*Doing stuff */
init{
//Open Connection and place it in scope
val req = RequesterModel(SimpleObjectProperty<Requester>(Requester("192.168.4.59")))
val scope = Scope()
setInScope(req, scope)
val overview = find<Overview>(scope)
//start Button
start.setOnAction {
replaceWith(overwiev)
}
}
class RequesterModel(val req : SimpleObjectProperty<Requester>) : ViewModel()
class Overview : View(){
override val root : VBox by fxml()
private val req : RequesterModel by inject()
//Doing other stuff
init{
//testing
println(req.req.value.address)
}
}
I was pretty dumb and didn麓t understand your examples but now I feel confident that won麓t happen again in the future. Thank you for the short reminder.
Great :) I'll close the issue.
Most helpful comment
After running several rounds around the block, I found the solution. Pretty simple but it works as intended. I will post parts of it here, you can keep it as an example if you want.
I was pretty dumb and didn麓t understand your examples but now I feel confident that won麓t happen again in the future. Thank you for the short reminder.