Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

View Params Object Not Updating in Subsequent openModal() Calls #443

Closed
bekwam opened this issue Sep 6, 2017 · 7 comments
Closed

View Params Object Not Updating in Subsequent openModal() Calls #443

bekwam opened this issue Sep 6, 2017 · 7 comments

Comments

@bekwam
Copy link
Contributor

bekwam commented Sep 6, 2017

    button( "Window #4" ) {
        setOnAction {
            val params  = mutableMapOf<String, String>()
            params["myval1"] = tf1.text
            params["myval2"] = tf2.text
            val window4 = find(ParamsView4::class, params)
            window4.openModal()
        }
    }

produces a ParamsView4 object with access to the two properties myval1 and myval2 as in

class ParamsView4 : View("Window #4") {

private var lbl : Label by singleAssign()

override val root = vbox {
    lbl = label {
        prefWidth = 200.0
    }
    padding = Insets(100.0)
}

override fun onDock() {
    val mv1 = params["myval1"] as String? ?: ""
    val mv2 = params["myval2"] as String? ?: ""
    lbl.text = mv1 + " " + mv2
}
}

However, a second button press resulting in a second find() will not update the params object in the View.

I think the problem is that the inheritParentHolder object is only setting the map in the View (Component) at instance creation and there is no reference kept which will update the map.

@Xfel
Copy link

Xfel commented Sep 10, 2017

Wouldn't it be more apropriate to use a fragment here?

@edvin
Copy link
Owner

edvin commented Sep 10, 2017

Yes it would. The behavior described her is by design. In general I think parameters should be avoided and replaced with injected ViewModels. Changing to Fragment is a reasonable thing to do, since parameters are only evaluated when the UIComponent is created.

@edvin
Copy link
Owner

edvin commented Sep 10, 2017

However, the result when using View is probably not what you expect, so I'll think about a better solution to this.

@edvin
Copy link
Owner

edvin commented Sep 10, 2017

I found a solution to this. Using the latest snapshot, parameters passed to views will now be reevaluated as you'd expect :)

@edvin
Copy link
Owner

edvin commented Sep 10, 2017

class ParamTestApp : App(ParamCallerView::class)

class ParamCallerView : View() {
    override val root = button("Open modal with param") {
        action {
            find<ParamReceiverView>(mapOf("name" to "Param ${LocalDateTime.now()}")).openModal()
        }
    }
}

class ParamReceiverView : View() {
    val name: String by param()

    override val root = vbox()

    override fun onDock() {
        with(root) {
            label(name)
        }
        currentStage?.sizeToScene()
    }
}

@edvin
Copy link
Owner

edvin commented Sep 13, 2017

@bekwam Did you have a chance to try this now?

@edvin
Copy link
Owner

edvin commented Sep 17, 2017

This is fixed in the 1.7.11 release.

@edvin edvin closed this as completed Sep 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants