I have a requirement to read the properties file, and according to properties from properties file I need to display them in the JSP. for this I need to point the exact matching of property with the instance variable from Javabean (The data for this object is coming from DB). If the properties in the properties file are fixed, then its not a big deal we can read each property and match with javabean's variable directly.
But in future the properties file can be changed with different properties, without changing the code I need to match them and need to display them with the data in JSP. But here the Javabean is reading all fields data from database.
It is not an advanced Java question. In fact, I'm not sure exactly what you are asking.
Are you looking for a way to have any changed values appear on already displayed JSPs? or something else?
Joined: Mar 19, 2008
actually our admin has to decide what UI elements needs to display on JSP, for this he is gonna change the properties file by including the new properties as I mentioned above or remove the existing properties. The thing is, we don't need to change the code every time, we need to display the properties and corresponding values from DB.
Ah, I think I see what you may be saying. The specific names of the properties may be fluid, so using a JavaBean is problematic because you don't want to have to modify the members of the JavaBean as the properties in the properties files change? Is that it?
If so, then yes, a JavaBean is not a good solution. Investigate the use of a Map instead, which is just as easy to deal with on a JSP as a bean (assuming that you are using the EL and not scriptlets).
And that there are taglibs out which can read properties files without any need to write extra Java code: the JSTL's fmt tagilb.
Joined: Mar 19, 2008
I can display the values from properties file, but here, if the admin wants to change the name of UI element and type to "radio", then we need to show them correspondingly, see the image here ,
So we need to change the givenname to completename and corresponding value from DB.
Here is the java code Im using to set the values . see the comment in the code.
I read the replies, but I didn't get what I expected.
JavaBean is fine because it needs to have all fields from DB, but on UI side we need to show some fields those are decided by our UI maintenance team by changing the properties in properties file.
Ex: right now they wanted to display First Name, Last Name , and telephone number. In case in future, if they wanted to display First Name, Full Name, and Address (instead Last Name and telephone number), then without changing our java code can we get replacing data from JavaBean(this is complete field list with data from DB) in order to display on UI side? (I can read properties, but the corresponding data how to pick dynamically)... Can we do it from java?
Joined: Oct 08, 2006
Instead of those nasty scriptlets in JSP, use JSTL/EL. The JSTL core taglib provides you under each the <c:if> and <c:choose> tags which will be very useful here.
If you want to go a step further --doing this stuff in a Java class and controlling it at a higher level-- consider a component based MVC framework like JSF.