Daemonite: Best Practice for Working with EJBs in CFMX Archive

Daemonite: Best Practice for Working with EJBs in CFMX Archive


Thursday, August 22, 2002
Best Practice for Working with EJBs in CFMX

If a shop was insistent on using EJB and CFMX together, would you generally recommend CFX or CFOBJECT? The question is really, what's the right tool for accessing EJB in CFMX? Here are some answers from the Macromedia dev team.

Answer from development...

"I can't think of reason *not* to use CFOBJECT. I would wrap all the JNDI and EJB-home access in a *private* method of a CFC and then have *public* worker methods in the CFC to access worker methods in the bean.

I've been asked the same question a few times on customer visits, and have given the same answer -- generally you'll want to use CFOBJECT or CreateObject(), because you can:

  • fully control the api
  • control the lifetime of the target object
  • share your POJO (plain old java object) with other java code in the same application

If in some cases the functionality really does belong in a tag wrapper, it's better to either:

  • write a jsp custom tag in java, then use it in cf, or
  • wrap the java object in a cfml custom tag

The above two approaches are superior to CFX tags because they allow tag bodies, looping, non-string-valued attributes, tag library packaging with cfimport, etc. You also don't need to register JSP or CFML custom tags in the admin. CFX's are basically obsolete.

The only time I recommend CFX's is if you absolutely must have some native code. In these cases, a CFX is sometimes easier to author than a JNI class, which is fine if you can live with the limitations."

Thanks to Sue Hove (Macromedia) for unearthing this little gem from anonymous sources.

Posted by modius at 02:58 PM | Permalink
Trackback: http://blog.daemon.com.au/cgi-bin/dmblog/mt-tb.cgi/35

Comments