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

Why SingleSelectionField not "only persists values when explicitly requested" like other fields? #51

Open
DQinYuan opened this issue Apr 4, 2020 · 0 comments

Comments

@DQinYuan
Copy link

DQinYuan commented Apr 4, 2020

My version:

    <dependency>
      <groupId>com.dlsc.formsfx</groupId>
      <artifactId>formsfx-core</artifactId>
      <version>1.3.1</version>
    </dependency>

For example:

import com.dlsc.formsfx.model.structure.Field;
import com.dlsc.formsfx.model.structure.Form;
import com.dlsc.formsfx.model.structure.Group;
import com.dlsc.formsfx.view.renderer.FormRenderer;
import javafx.application.Application;
import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class FormsfxApp extends Application {

    public static void main(String[] args) {
        launch(args);
    }


    @Override
    public void start(Stage primaryStage) throws Exception {

        StringProperty name = new SimpleStringProperty("my name");
        name.addListener((observable, oldValue, newValue) -> System.out.println("new name:" + newValue));
        IntegerProperty age = new SimpleIntegerProperty(10);
        age.addListener((observable, oldValue, newValue) -> System.out.println("new age:" + newValue));

        ObjectProperty<String> selected = new SimpleObjectProperty<>("aaa");
        selected.addListener((observable, oldValue, newValue) -> System.out.println("select:" + newValue));
        ListProperty<String> items = new SimpleListProperty<>(
                FXCollections.observableArrayList("aaa", "bbb", "ccc")
        );

        Form form = Form.of(
                Group.of(
                        Field.ofStringType(name),
                        Field.ofIntegerType(age),
                        Field.ofSingleSelectionType(items, selected)
                )
        ).title("test persist");

        BorderPane borderPane = new BorderPane();
        borderPane.setCenter(new FormRenderer(form));
        primaryStage.setScene(new Scene(borderPane, 1000, 600));
        primaryStage.show();
    }
}

screen shot

Other Fields like StringField and IntegerField change property only when form.persis() is called explicitly. But selected property in SingleSelectionField is eagerly modified in every time I select other item in combo box.

I find there is a persistentSelection field in SingleSelectionField:

protected final ObjectProperty<V> persistentSelection = new SimpleObjectProperty<>();

But why it is not exposed for user?

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

No branches or pull requests

1 participant