[jboss-user] [JBoss Seam] - Re: ResourceBundle in Database

Zerg-Spirit do-not-reply at jboss.com
Tue Jul 3 10:34:16 EDT 2007


Ok, sorry again for the multi posts, but I think I finally found out what was wrong.

I think I simply can't retrieve my EntityManager by injection at all.
Here's what I understood.

First, seam load the overrided Seam.ResourceBundle:

@Scope(SESSION)
  | @BypassInterceptors
  | @Name("org.jboss.seam.core.resourceBundle")
  | public class ExtendedResourceBundle extends org.jboss.seam.international.ResourceBundle{
  | 	
  | 	@Override
  | 	protected ResourceBundle loadBundle(String bundleName) {
  | 		try {
  | 			ResourceBundle bundle =
  | 				ResourceBundle.getBundle(bundleName,
  | 						Locale.instance(),
  | 						Thread.currentThread().getContextClassLoader(),new DBControl());
  | ...
When the DBControl is instanciated, the 'newBundle' method is then automatically called in order to load an actual ResourceBundle:

@Override
  | 	public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)throws IllegalAccessException, 
  | 	InstantiationException, IOException {
  | 		if ((baseName == null) || (locale == null) ||
  | 				(format == null) || (loader == null)) {
  | 			throw new NullPointerException();
  | 		}
  | 
  | 		return new DBResourceBundle(locale);
  | 	}...
At that point, I instanciate my DBResourceBundle, which is an extended java.util.ResourceBundle.

So, thanks to that implementation, when any jsf pages reference to the object 'messages' (for exemple: <h:outputText value="#{messages['something']}" />) it references to the object created at that line:
return new DBResourceBundle(locale);

So basically, any injected property isn't reachable, cause this is not the Session Bean at all, although the class is referenced as one. I guess when you manually instanciate a new object, even if its class has some annoation declaring it as a Session Bean, it's not. It's simply a Java object.

So when further in the application I make a call on the @Create method, the method is called without problem and do whatever it has to do (in my case, loading my messages from the DB thanks to the EntityManager), but it is all wrapped in my Session Bean, NOT in my Java Object referenced by 'messages'.

If I understood it right, I then have to answer one simple question:
Is it possible to retrieve the EntityManager without using the Seam injection mecanism?
If not, I'll simply use plain java code to connect to my base, but it'll be quite dirty.

Finally, I hope I get all that right =)

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4060001#4060001

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4060001



More information about the jboss-user mailing list