Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to read instance variable dynamically?

 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Here is the properties file.


Here is the Javabean class:



Could some one please help on this
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on advanced Java.

For more information, please read this.

This post has been moved to a more appropriate forum.

 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not type of UI question, and its more like programming side. Hence I used java advanced forum
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. The fact that java.util.Properties implements Map may make this very simple for you.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And that there are taglibs out which can read properties files without any need to write extra Java code: the JSTL's fmt tagilb.
 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

(
 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP code:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you even read the replies?
 
Simpson Kumar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maris Orbidans
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sudhakar Kumar wrote: (I can read properties, but the corresponding data how to pick dynamically)... Can we do it from java?


Do you want to specify in config file which property of UserDN will be shown in each UI field ?

You need to use reflection or use Commons BeanUtils.




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic