vendredi 3 octobre 2014
JavaFX persistence made easy with JCROMfx
We recently decided to test a new persistence solution: Java Content Repository and especially the ModeShape implementation. Java Content Repository are designed to store content and metadata about this content. It looks like they are a good solution to persist application data, especially if you are manipulating lot of files and binary data.
The tree structure of a Java Content Repository allow a pretty simple mapping of graphs of Java objects. Mapping can be done either manually or using an object mapping framework. It looks like that one of the most used JCR mapping framework is JCROM. JCROM is described as a lightweight framework for mapping Java objects to/from a Java Content Repository (JCR).
JCROM was initially designed to handle most basic Java types but it was in 2008 when JavaFX did not exist! So we forked this excellent project and tried to extend it to support JavaFX properties...and it turned out to be pretty easy, even for JavaFX collections.
So we are pleased to announce that you can use JCROMfx to map your Java objects with JavaFX properties directly to/from a JCR repository! Just annotate your JavaFX properties and you are ready to persist them. This include all basic JavaFX properties (StringProperty, IntegerProperty,...), collections (ListProperty, MapProperty) and object properties of enum or of other objects (using @JcrChildNode)
Just to give you an overview of how a bean looks like with JCROM annotation & JavaFX properties :
Feedback is welcome :)
mardi 23 septembre 2014
FXForm2 sampler
These samples were designed to help you using FXForm2 and to discover all of its features. FXForm2 can be highly customized to generate most of the forms you need; this sampler should help you to understand which features you need and how to configure your form.
We have covered some frequent cases we use here at dooApp, but feel free to ask for more examples!
How to test it?
- Clone the FXForm2 repo
- Run mvn exec:java in the samples directory
- Enjoy
jeudi 24 juillet 2014
Wisdom framework with apache shiro
First, what is Wisdom ?
Wisdom is a young but promising Java web framework, to develope quickcly modular and dynamic web applications. You can check Wisdom website for more informations.
Unfortunaly it does not include yet users management. That's why I decided to try to embed apache shiro inside my project.
The goal is to manage multiple users with different roles and to be able to authenticate them and display different template according to their roles.
In this example I create some users during shiro initialisation, but in the next article I'll use a real database.
The sample project is available here
Now let's take a look at the code.
First the ShiroActivator class used to initialize shiro
This is just basic stuff here, it create 2 roles and 2 users. Just with this, you're done ! you can use shiro now.
Then when you submit your form login this route will be called.
As you can see it's really simple, in 3 lines of codes you're authenticated. The exceptions here will display a flash message on the view in case of error like wrong password.
Once you're logged you'll be redirected to the protected page which displays different content whether you are admin or not.
But how is the route protected if you're not logged ?
Here I do a combination of wisdom and shiro features. This is my protected route :
As you can see there is an annotation @Authenticated. It comes from wisdom. You have to specify the name of your authenticator implementation. This is mine
So in the getUsername() method, I simply use shiro to retrieve the current user, if it returns null, so you're not logged and the onUnauthorized method will be called. Otherwise the controller route will be executed correctly.
Once you're logged, you'll have a different message if you're admin or guest. To achieve this I add some if statements in my template.
As you can see on the ProtectedController, on method return we have a new UserHelper in our parameters. that mean you will be able to call methods of this class on our template to check the role of the current user.
So your template will know which statement to use depending of the user role.
This is everything you need. I let you check by yourself on the sample project the logout method cause it's not really complicated.
Have fun with this great framework !
jeudi 28 novembre 2013
FXForm: two releases and a lot of new features
Get ready for JavaFX 8
- FXForm 2.2.x for JavaFX 2.2 (latest version: 2.2.4)
- FXForm 8.0.x for JavaFX 8.0 (latest version: 8.0.1)
Improved data validation
Class level constraint validation
Strict constraint versus warning constraint
Multiple bean source
@Adapter
Better handling of bound and read-only properties
New NodeSkin
ListProperty support
mercredi 17 juillet 2013
Natural language search in FXML
Traceability
- program comprehension,
- maintenance,
- requirement tracing,
- impact analysis,...
Classical approach
- the developers might not always use the exact and precise domain terminology
- the code and the specification (e.g. a regulation) might be in different languages
Our approach
Process
- Index resource bundles using Apache Lucene
- Query the indexed bundles in natural language and retrieve the best matching labels and associated keys
- Retrieve code elements by analyzing key usages (either statically by analyzing code or dynamically by registering stacktraces of calls to ResourceBundle.get())
IntelliJ plugin
And what about JavaFX?
So, we realized that our plugin can also be used to easily retrieve FXML files associated to user interface labels, even if the query is approximate !
Don't lose time anymore trying to identify which FXML file to open when you want to modify the user interface ! Type in what you are looking for (e.g. some words that you see in the user interface) and let the plugin find it for you!
This is really handy for developers starting working on an existing project or for maintenance.
Try it yourself
- Install the plugin from IntelliJ
- Type "Ctrl+Shit+S" to open the input dialog
- Type your query in natural language
- Explore the results !
jeudi 27 juin 2013
FXBinding, the binding you need
I have an List ObservableList<XYChart.Data<Number, Number>>. I want to compute the average value of XValueProprerty for all Data contained into the list :
Without FXBinding :
See full code hereAs you can see, it doesn't work :/
The binding is invalid only when the list changes, so when the XValue of a Data changes, nothing append.
I have to register every XValueProperty() into the bind() method :
Now it works for all Data that was into the list at the beginning, but not for all added (or removed) Data after the init of the Binding
Let's make it work :
See full code hereWhile the complexity of your model is growing, you will have to register many listeners and the code is going to be less readable, less maintainable and less bug proof.
With FXBinding
Now let's replace our DoubleBinding by a magical FXDoubleBinding, it's 4 time step :
- Replace
new DoubleBinding()bynew FXDoubleBinding() - Change the method name from
computeValue()tocompute() - Remove
{bind(...)}and replace it by theconfigure()method - In the
configure()method calladdObservable()instead ofbind()
Every time the binding is becoming invalid, we will reconfigure it, so it's always a cool binding.
We will never have to add a listener even in a very complex model
An other example :
See full code hereGet FXBinding here
jeudi 20 juin 2013
ListProperty vs ObjectProperty
In the world of JavaFX, when you need to use an ObservableList with the Property pattern, you write the following :
ObjectProperty<ObservableList<T>>
To be notified when the list content is modified, you can register a ListChangeListener on the ObservableList referenced by the ObjectProperty using the getter.
You can also register a ChangeListener on the ObjectProperty to be notified when the instance of ObservableList referenced by the ObjectProperty is modified.
- If you add an element or more, your ListChangeListener will be notified.
- If you change your ObservableList instance, your ChangeListener will be called.
Why ? cause the equals method implementation return true between the two ObservableList.
So as you see... using an ObservableList with the Property pattern, is not really cool.
This is a problem, isn't it ??
Oh Legolas wants to help us. So listen what he says:
Replace our ObjectProperty<ObservableList<T> by a ListProperty<T>. ListProperty implements both Property<ObservableList> and ObservableList and makes the whole wrapping really transparent for the developer, taking care of the previous ListChangeListener manipulation automatically !
When you do this, adding an element will notify the listener, and changing the ObservableList instance will call the listener to. And if you add an element after changing the list instance, no problem! the listener will also be notified of the change in the new list instance. No need to register a new Listener on the new List, the ListProperty manages it for you !









