-
1. Re: To access a EJB within a Converter-Class
healeyb Feb 19, 2012 7:59 AM (in response to enrix)1 of 1 people found this helpfulHenry, it's an annoying oversight that @EJB doesn't work, but you can add something like this in the
converter constructor:
private YourEjbClass ejb;
public YourConverter() {
if (ejb == null) {
try {
ctx = new InitialContext();
ejb = (YourEjbClass) ctx.lookup("java:global/com.myproject_MyProject_war_1.0.0/YourEjbClass");
} catch (Exception e) { // poor example of exception handling!
Log.log(e.getMessage());
}
}
}
The glassfish app server outputs the portable jndi names in the server log at startup time for all ejbs, hopefully similar
functionality exists for other app servers.
I use Myfaces CODI http://myfaces.apache.org/extensions/cdi/ which allows me to @Inject ejbs into converter
classes that are annotated with the @Advanced annotation (I think this may depend on whether you're using
OpenWebBeans or Weld as the CDI implementation, as a glassfish user I use Weld and require @Advanced).
Regards,
Brendan.
-
2. Re: To access a EJB within a Converter-Class
enrix Feb 21, 2012 8:59 AM (in response to healeyb)Brendan, thanks for the helpful answer. For the time i have chosen the InitialContext-Lookup and it works trouble-free. Soon I'll be looking closer for CODI. It should also work in Jboss AS7, but befor i have to change my pom.xml. I have visited your Link an have found maven-build-information in the project summary. Maybe, if you have time, you can provide your code from your pom.xml.
For those how are often reliant on a InitialContext-Lookup, I've got a tip: During the deploy-process the AS shows the right JNDI-Namespaces (java:global/..., java:modul:/..., java:app/...) of your EJB's within the open terminal.
Best regards an good cooperation continues
Henry