When I develop XPages applications I always use properties files, stored in the files section under Resources in the application.
When the application is finished I can easily copy the properties file and create a new language file, and let it controlled by a Language bean to display the labels in the application based by a key. It is a easy way to give the application multi language support.
Back in my head there was all the time the need to give an administrator or editor of the application more control of the labels.
Over the weekend I made a ProperrtyHandler bean, but first I created a Property class. This is a very basic class, with only 2 properties, label and value.
loadPropertiesFromView method
This method is to collect all the documents from the view and store the value and key in the TreeMap. This method is triggered by the creating of the bean, so everything is in place to serve the front end
[dropshadowbox align=”none” effect=”lifted-both” width=”600px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ][/dropshadowbox]
loadPropertiesFromFile method
This method is to collect all the rows from the default property file, located in the files section and store these values in a TreeMap, with the key as key and a Property object as Value.
Also the code store the key and value in documents, so the user can edit the lablels.
[dropshadowbox align=”none” effect=”lifted-both” width=”600px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ][/dropshadowbox]
Integrate everything
In my Language I made a small enhancement, to not collect the label from the property file, but from the PropertyHandler. In this way I don’t have to change the whole application.
[dropshadowbox align=”none” effect=”lifted-both” width=”600px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ][/dropshadowbox]
And off course my Front end
To make it possible to control and edit the label values of my properties, I made 2 XPages. An overview with buttons to load the backend properties file.
[dropshadowbox align=”none” effect=”lifted-both” width=”600px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ][/dropshadowbox]
a XPage to display the labels and key. Only the label is editable, because the key is needed in the application When the document is saved, the property in the TreeMap will also be updated.
[dropshadowbox align=”none” effect=”lifted-both” width=”600px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ][/dropshadowbox]
As requested, I put the Java classes in GIT repository
Hi Frank,
how can I save a changed properties file?
Thanks a lot!
Markus
I have looked into that, but till now I was not able to save the changes back to the properties file.
This weekend I will have a next attempt, because I now know more about this process. In my current project at a customer I am into JSF.
I will keep you posted.