Sunday, February 16, 2014

Separate Properties from WAR

Separating properties from wars, there are many reasons and there are many ways. If you are still generating multiple wars, each for each level, you are out. Catch up, my friends, it is already the year of 2014.

Among all these almighty solutions, there is this simple and easy one, with JBoss 5.1.

First create a myapp-service.xml like this,



This myapp-server.xml will be deployed to JBoss deploy folder same as the war file.

Then in the appContext.xml, add a PropertyPlaceholderConfigurer.



Now you can use these properties in the appContext.xml like that,



To use the properties like myapp.props1, you need to define the field in the bean class like "private String[] props1;" then your props1 will be an array of aaa and bbb.

Now let's see that aaa and bbb need to be populated into a drop down list in HTML page.

First, create a JSON web service to serve the AJAX request. Remember, aaa and bbb will be sent down as {"aaa", "bbb"}.

In the HTML page, it will look like,



After selection, use $("#mydropdownid").val() to obtain the selected value. Remember it will be "aaa" or "bbb", not aaa or bbb. So when post it back to web service, use it straight forward, don't JSON stringfy it.

No comments: