wood burning stoves 2.0*
The moose likes JSF and the fly likes How to optimize code using JSF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to optimize code using JSF" Watch "How to optimize code using JSF" New topic
Author

How to optimize code using JSF

Fabio Cunha
Greenhorn

Joined: Mar 25, 2011
Posts: 12
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

Joined: Jun 25, 2001
Posts: 15632
    
  15

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Fabio Cunha
Greenhorn

Joined: Mar 25, 2011
Posts: 12
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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to optimize code using JSF
 
Similar Threads
JSF Mental Block
loading xml file problem in jboss developer studio managed bean
How to use inner join with hql query
Bean value not maintained in RequestScoped
@ViewScoped not working