Unable to Invoke CDI StateLess EBJ from JSF
schanamolu Sep 17, 2012 2:07 PMGuys,
Please check the attached code both xhtml and Stateless EJB 3.1 or CDI. I try to invkoe statesless EJB through CDI injection, but its not invoking nor displaying output. Let me know any cofiguration
===============================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
>
<h:body>
<ui:composition template="template/common/template.xhtml">
<ui:define name="content">
<h:messages />
<h:outputText value="#{actorService.greeting}"/>
</ui:define>
</ui:composition>
</h:body>
</html>
=========================================================
package com.ibytecode.businesslogic;
import java.util.List;
import java.lang.Short;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import com.ibytecode.entity.Actor;
@Stateless
@Named(value = "actorService")
public class ActorBean {
/* public ActorBean() { }*/
@PersistenceContext(unitName = "FirstEJBsProject")
private EntityManager entityManager;
private String greeting;
public String getGreeting() {
return greeting;
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
public void saveActor(Actor actor) {
entityManager.persist(actor);
}
public Actor findActor(Actor actor) {
Actor p = entityManager.find(Actor.class, actor.getActorId());
return p;
}
public ActorBean() {
Actor actor = new Actor();
actor.setActorId(new Short("201"));
actor = findActor (actor);
if (actor != null) {
greeting = "Hello, " + actor.getFirstName() + " " + actor.getLastName() + "!";
} else {
greeting = "No such user exists! Use 'emuster' or 'jdoe'";
}
}
public List<Actor> retrieveAllActors() {
String q = "SELECT p from " + Actor.class.getName() + " p";
Query query = entityManager.createQuery(q);
List<Actor> actors = query.getResultList();
return actors;
}
}
Thanks,
Sreedhar
'
Thanks,
Sredhar
-
sample.xhtml.zip 467 bytes
-
ActorBean.java.zip 756 bytes