This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to optimize code using JSF  RSS feed

Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating an application using Hibernate and JSF, but at certain times to write data to some tables, I need to pull information stored in other tables

this is the ManagedBeans that I use to pull data from a particular table in my database

but where the line has the following code

I use a fixed class, someone would have an idea how I could pass it dynamically, I ask this because otherwise I'll have to create a ManagedBean for each class that I need to list the database

sorry for the bad english...
i´am brazilian
Posts: 19660
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can inject the name of the class as a JSF ManagedProperty. However, note that this requires multiple instances of the seuManagedBean. That's not that bad, however, since it's not a very big bean.

you should not use a lower-case letter as the initial letter of the class name, however. That violates Java's coding standards and may even cause the ManagedBean mechanism to fail. A proper name would be something like: "SeuManagedBean", which the JSF bean instantiator would then catalog under the name "seuManagedBean".

However, if you take my original advice, which requires multiple instances, you'll need to configure this bean in faces-config.xml, since you'll need each instance to be cataloged under a unique bean name, and the annotation processor cannot handle that, not can it handle the multiple values for the injected ManagedProperty.
Fabio Cunha
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, you are right, I will follow the java coding standards, i will rename the "seuManagedBean" to "SeuManagedBean", but I don't know how implement faces-config.xml, how i can implement that?

Another thing, take a look in code below: it's the same logic as the "SeuManagedBean":

I use the same logic as the "SeuManagedBean", but they call two methods

and each of them call a diferent criteria

This way, everytime i need to populate a selectonemenu, the code will call all methods(each accesses the database to retrieve the records), my application may become slow?

I understand your idea about the config in faces-config.xml, but i don't know how to implement.

Could you help?

This in my xhtml file that i use with ListaEstado

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!