This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to optimize code using JSF

 
Fabio Cunha
Greenhorn
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
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
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
Greenhorn
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic