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

Single Selection Type Fields Not Persisting #2

Closed
wemgl opened this issue Sep 18, 2017 · 9 comments
Closed

Single Selection Type Fields Not Persisting #2

wemgl opened this issue Sep 18, 2017 · 9 comments
Assignees
Labels

Comments

@wemgl
Copy link

wemgl commented Sep 18, 2017

I just started using FormsFX and it's been great so far. I was able to create a form with string, integer, and boolean type fields and them update a model via properties with no issues. I run into a problem though, when I try to add a single selection type field. The following are the snippets of code showing what I did (I basically followed what's in the demo application):

    private final ListProperty<Integer> allServings =
            new SimpleListProperty<>(FXCollections.observableArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
    private final ObjectProperty<Integer> serving = new SimpleObjectProperty<>(1);

   /**
     * References the <code>Form</code> that is bound to this <code>Recipe</code>.
     *
     * @since 1.0.0
     */
    private Form formInstance;

    /**
     * Retrieves or creates an instance of a FormFX form using the given <code>Recipe</code>.
     *
     * @return An instance of a FormFX form using the given <code>Recipe</code>.
     *
     * @since 1.0.0
     */
    public Form getOrCreateFormInstance() {
        if (Objects.isNull(this.formInstance)) {
            createForm();
        }

        return this.formInstance;
    }

    /**
     * Helper method to initialize the FormFX form field of this <code>Recipe</code>.
     *
     * @since 1.0.0
     */
    private void createForm() {
        this.formInstance = Form.of(Group.of(
                Field.ofStringType(titleProperty())
                     .label("Title")
                     .placeholder("e.g. Chicken Wings")
                     .required("A title is required for all recipes."),
                Field.ofStringType(descriptionProperty())
                     .label("Description")
                     .placeholder("e.g. Delicious Honey BBQ wings")
                     .required("A description is required for all recipes."),
                Field.ofIntegerType(caloriesProperty())
                     .label("Calories")
                     .placeholder("e.g. 500")
                     .span(ColSpan.HALF)
                     .required("The number of calories is required for all recipes."),
                Field.ofIntegerType(cookTimeProperty())
                     .label("Cooking Time")
                     .placeholder("e.g. 60")
                     .span(ColSpan.HALF)
                     .required("The total cooking time (in minutes) is required for all recipes."),
                Field.ofSingleSelectionType(allServingsProperty(), servingProperty())
                     .label("Serving Size")
                     .placeholder("Serving Size")
                     .required("The serving size is required for all recipes."),
                Field.ofStringType(directionsProperty())
                     .label("Cooking Directions")
                     .placeholder("e.g. Bake at 375 degrees in the over for an hour and a half.")
                     .required("Cooking directions are required for all recipes."),
                Field.ofBooleanType(publishedProperty())
                     .label("Publish Recipe")))
                                .title("Recipe Form");
    }

    public Integer getServing() {
        return serving.get();
    }

    public void setServing(Integer serving) {
        this.serving.set(serving);
    }

    public ObjectProperty<Integer> servingProperty() {
        return serving;
    }

    public ObservableList<Integer> getAllServings() {
        return allServings.get();
    }

    public void setAllServings(ObservableList<Integer> allServings) {
        this.allServings.set(allServings);
    }

    public ListProperty<Integer> allServingsProperty() {
        return allServings;
    }

Here is the method that I use to save the form fields to the database:

    @FXML
    public void save(ActionEvent event) {
        this.recipe.getOrCreateFormInstance().persist();
        if (!this.recipe.getOrCreateFormInstance().isValid()) {
            return;
        }

        if (this.recipe.getId() == 0) {
            saveRecipe(this.recipe);
        }
        else {
            updateRecipe(this.recipe);
        }
    }

All other form fields save except the serving field. Am I doing anything incorrectly based on the code I've shared? Please let me know if you need anymore context.

@wemgl
Copy link
Author

wemgl commented Oct 29, 2017

I see this issue has been tagged as a bug, have you had any luck figuring out that cause of it? Sorry, I wasn't able to follow-up sooner with anymore helpful information about it in my side.

@martinfrancois
Copy link
Contributor

@wemgl we faced the same issues as you did (along with some others) and after a long time of trying to fix the bug, we think that it should finally work now.
Can you please try if your problem still occurs, if you use the latest master build from this repository: https://github.com/FHNW-IP5-IP6/formsfx
Thanks in advance!

@wemgl
Copy link
Author

wemgl commented Dec 2, 2017

@martinfrancois Thanks for sharing your fix. It's working great. I did get a failing test when I built the latest master though. Here's the stacktrace I got:

itemsTest(com.dlsc.formsfx.view.controls.SimpleControlTest)  Time elapsed: 0.028 sec  <<< FAILURE!
java.lang.AssertionError
	at org.junit.Assert.fail(Assert.java:86)
	at org.junit.Assert.assertTrue(Assert.java:41)
	at org.junit.Assert.assertTrue(Assert.java:52)
	at com.dlsc.formsfx.view.controls.SimpleControlTest.itemsTest(SimpleControlTest.java:83)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

It was only after I skipped the tests that I was able to build the jar and add it to my project's class path and saw that your fix was working.

@martinfrancois
Copy link
Contributor

@wemgl glad to hear that! Thanks for getting back so quickly and reporting your experiences.
I noticed there were some changes that weren't getting merged properly into the master branch from the branch where we fixed the bug. I now added them, could you please try again, building from the master branch and see if it still fixes your issue? It should now build without any tests failing.

@wemgl
Copy link
Author

wemgl commented Dec 5, 2017

@martinfrancois I've downloaded the most recent master and everything works fine. I didn't have to skip any tests. Any plans to have this merged into this repo's master? I see they finally have it working with Maven. Also, thanks for fixing this!

@dlemmermann
Copy link
Collaborator

@martinfrancois would you please be so kind to provide the same fix to this repository please?

@martinfrancois
Copy link
Contributor

@wemgl You're welcome! Glad to hear it's working fine. I just submitted a pull request to this repository (see #6). As soon as it's merged, it should be available with Maven as well.

@dlemmermann
Copy link
Collaborator

It will be available on Maven once I deployed a new release :-) Hope to find some time for that today.

@dlemmermann
Copy link
Collaborator

I went ahead and deployed version 1.1.

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

4 participants