Skip to content

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

@DQinYuan

Description

@DQinYuan

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions