dooApp/FXForm2

Extending the FormFactory annotation

Closed this issue · 5 comments

Hello there, first of all. The project is a lifesaver, and amazing.

I would very much like to contribute with it, we're currently implementing some custom form components using the controlsfx Controls. But our components need a little more information.

Is there anyway for us to implement, or extend the way of using the FormFactory annotation based for some fields, where we can use some extra parameters to it?

Those would go to the FieldFactories, so they can build the controls properly.

I was looking for a way to do it, but I felt quite lost with some part of the code, what classes should
I extend for implementing this feature?

Thanks for the support, and for helping the JavaFX community!

Hi Rodney,

Extending an annotation is not possible in Java, so another approach would consist of using another annotation to provide the additional data you need on the field.

Then, you can read your custom annotation in the init method of your FXFormNode. In the init method you have access to the Element which encapsulates the field on which the control is being used. There, you can call #getAnnotation on the element to retrieve your custom annotation if defined on this field.

I have updated the CustomFactoryForm sample with an example demonstrating how to do this (see TextFieldWithPromptTextFactory), tell me if this fits your needs.

Feel free to submit a pull request if you want to contribute to FXForm and to share some custom form components !

Hello Amischler,
I think that would do! Kind of exactly what I need!
I will take a look on that, and certainly will contribute with the pull requests!
Thanks a lot!

Hello Again.

I'm receiving this error with simpleObjectProperties

ADVERTÊNCIA: No adapter between types class javafx.beans.property.adapter.JavaBeanObjectProperty and class javafx.beans.property.SimpleObjectProperty was found (to adapt com.dooapp.fxform.model.impl.java.JavaBeanObjectPropertyElement@261bff6e and FXFormNodeWrapper{node=PopOverField[id=testeModel-form-editor, styleClass=text-input text-field custom-text-field form-editor], property=ObjectProperty [value: João]})
Make sure to register the required adapter in DefaultAdapterProvider either in the global or in the user map. See FXForm#setAdapterProvider

What should I do?

Thanks for the help!

Hi,

FXForm uses adapters to convert values between the property exposed by the view and the model property. In your case, the view property is an ObjectProperty and the model property seems to be an Object wrapped automatically by FXForm into a JavaBeanObjectProperty.

For your case there is no explicit adapter registered, so FXForm is using the default adapter which is a one to one adapter, performing non conversion. This is just a warning and it should work in your case.

However, I would recommend you to use JavaFX properties in your model instead of simple Objects, because the JavaBeanObjectProperty can not listen to the field and thus changes in your model won't be reflected into the view.

I'm closing this issue, feel free to open other issues if you encounter other difficulties implementing your factories.