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 !
lundi 1 avril 2013
FXML + FXForm2 = Developing forms has never been so easy!
- write your model bean
- design your form in FXML
- FXForm2 do the rest!







