Spring MVC and FlashAttributes

A simple solution with Sping MVC to print info messages to the user after a redirect is RedirectAttribute. They will only show up a single time after a redirect. Spring initializes RedirectAttribute in the method param.

Example for setting a flash attribute:

and display it with the following code in your view

Testing it

The messages are attached as an attribute in the request so they can be easily tested in a unit test:

One thing is a bit wired. If spring initialize RedirectAttributes in the method and there are no errors in the BindingResult, it “feels” like there is some kind of redirect simulation. The ModelMap is empty after that and BindingResult is null. Without RedirectAttributes the BindingResult remains without errors in the model map. I think it’s more realistic with an empty ModelMap after the redirect, but I can’t understand why the behaviour is different?

Getting BindingResult of Spring MVC in JUnit-Test

I found several variants of how to get Spring MVC BindingResult in a JUnit-Test but most of them doesn’t look very handy to me. But there is a very simple solution, too. The BindingResult is stored in the ModelMap with the Name:

Example

Method to test:

Test:

 

How to display Liferay EE license Information

I haven’t found a button or something in the control panel to display information about the current installed ee license until now. It happens to me that the date in the plain text information of the license file differs from the real license expiration date so I’m always nervous about license type and license expiration date. But there is an url to display the license information. Liferay redirects every request to this url if there are to much requests to a developer license or if the server license is expired. To prevent this you should check your license immediately after the license installation.

Log in as an admin and have a look on:

http://example.com/c/portal/ee/license

A valid server license looks like:

A valid developer license looks like:

SQL-Statement to give administration role to a regular liferay user

To change a regular liferay user to an administration account – for example if you are still able to register to your portal but have forgotten your admin password – use the following sql-statemnet.

Don’t forget the database cache! (restart)

Konvertieren einer Liferay-Datenbank von Latin-1 auf UTF-8

Auf dem diesjährigen Liferay-Symposium meldeten sich einige User beim Q & A mit Brian Chan mit der Frage, wie man eine fälschlich in Latin-1 angelegte Datenbank in UTF-8 konvertiert. Da wir das soeben bei einer Datenbank durchgeführt haben, hier eine kurze Anleitung:

Zunächst bitte sicherstellen, dass die Konsole auf UTF-8 gestellt ist. Wenn man den Datenbankdump mit vi aufmacht und Sonderzeichen richtig angezeigt werden, dann stimmt’s. ;-)

Liferay runterfahren, Datenbank-Dump ziehen und sichern:

dump.sql mit vi aufmachen und tabellendefinitionen per Suchen & Ersetzen ändern:

Datenbank löschen und diesmal richtig anlegen:

Dump wieder einspielen:

Jetzt Liferay wieder starten und dann sollte es das schon gewesen sein.

P.S.: Diese Anleitung ist eigentlich nicht Liferay-Spezifisch und sollte auch bei anderen Anwendungen helfen.