I have a web project that has FacesValidator, this validator needs to access an EJB service to verify if a record exists. Unfortunately, I cannot inject my enterprise beans since the validator is not a managed-bean, so I’m trying to access it via InitialContext. I’ve tried different combination from http://docs.oracle.com/javaee/6/tutorial/doc/gipjf.html but failed.
What works is this format:
java:global/myProject-ear-1.0.0/myProject/MyService!com.czetsuya.myProject.service.membership.MyService,
My question is can it be simplify? Seems too long.
Thanks,
czetsuya
Look at the server logs. A bit decent EJB container (at least, Glassfish 3 and JBoss 6/7 do), logs all available JNDI names of the EJB during EJB deployment step. Provided that the validator is properly been put in the WAR and the EJB has a
@Localinterface, then the shortest JNDI name would be thejava:appone which should in your case have beenjava:app/myProject/MyService.A completely different alternative is to just make the validator a JSF or CDI managed bean instead, so that you can just use the
@EJBannotation.and reference it by
bindinginstead ofvalidatorId:Note that from JSF 2.2 on, you should be able to inject
@EJBin a@FacesValidator(and@FacesConverter).See also: