-
1. Re: Backing beans
ssilvert Mar 9, 2007 2:39 PM (in response to raskri)Seam ships with lots of good examples.
http://labs.jboss.com/portal/jbossseam
For general JBoss/JSF info, see http://jsf.jboss.org
Stan -
2. Re: Backing beans
raskri Mar 10, 2007 10:35 AM (in response to raskri)I know about Seam but i cant use Seam in this case. It's a school project. Not allowed. They teach EJB 2.0 witch sucks, so i started to use 3.0. Just need some examples where an entity bean is persisted through a session bean through jsf...
-
3. Re: Backing beans
raskri Mar 11, 2007 9:57 AM (in response to raskri)OK here is some of my code:
INTERFACE:
@Local
public interface NewSession {
String addFugl(String norsk, String latinsk);
}
BEAN:(Fugl is an EntityBean)
@Stateless()
public class NewSessionBean implements NewSession {
@PersistenceContext
private EntityManager em;
public NewSessionBean() { }
public String addFugl(String norsk, String latinsk){
Fugl fugl = new Fugl();
fugl.setLatinskNavn(latinsk);
fugl.setNorskNavn(norsk);
em.persist(fugl);
return "success";
}
}
BACKING BEAN:
public class FuglBM {
@EJB()
private NewSession bean;
private String norsknavn;
private String latinsknavn;
public FuglBM() {
}
public String addfugl(){
return bean.addFugl(norsknavn, latinsknavn); <--NullPointer(line 21)
}
public String getNorsknavn() {
return norsknavn;
}
public void setNorsknavn(String norsknavn) {
this.norsknavn = norsknavn;
}
public String getLatinsknavn() {
return latinsknavn;
}
public void setLatinsknavn(String latinsknavn) {
this.latinsknavn = latinsknavn;
}
}
FROM MY JSF I CALL:
(FuglBM is set in the faces-config.xml)
..
<h:inputText value="#{FuglBM.norsknavn}" />
..
<h:inputText value="#{FuglBM.latinsknavn}"/>
..
<h:commandButton value="Submit" action="#{FuglBM.addfugl}" />
->user is redirected in the faces-config navigation on outcome "success".
I GET ERROR:
java.lang.NullPointerException
managed.bean.FuglBM.addfugl(FuglBM.java:21)
It looks like the @EJB annotation is not giving a refferance to the bean...
-any tips? -
4. Re: Backing beans
raskri Mar 11, 2007 11:53 AM (in response to raskri)OK.... I got the solution after some googling.(FGI)
I tried to create the connection by adding:
private NewSession bean = new NewSessionBean();
->but this didn't "create" or "inject" the EntityManger, so i got another NullPointerException saying that EntityMager was NULL.
In the web.xml web-app tag, NetBeans(IDE)automatically adds:
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
The 2.4 version does not support annotations.
Therefore the web-app tag has to be changed to:
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
->This makes my backing bean's annotation read, and so the EntityManager is "created", and my "Fugl-EB" is persisted into the DB!!!! -
5. Re: Backing beans
ssilvert Mar 11, 2007 5:09 PM (in response to raskri)That's a good tip. Thanks for sharing it. I bet many others will have the same problem. So, I've updated our wiki for http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossWithJSFCDDL
Stan
http://jsf.jboss.org -
6. Re: Backing beans
zhamdi Aug 28, 2007 5:38 AM (in response to raskri)Hi Raskri,
Your post was really useful for me, I found it as the second link in my first googling attemp (jboss "backing beans" admin) ;-).
I'd like to know why JBoss doesn't supply a richer admin interface: there's no way to see which JNDI path was applied to a resource, I still didn't find where to look in the jmx or web console to see the deployed Backing beans, there's a node for the war but (it shows only the servlets) no node for the ejb jars... The onfo is really exploded :-/
Does someone maybe know about another "independent" admin console developed to fill these blanks?...
Regards,
Zied Hamdi