I know a lot of questions are already on StackOverflow about this but I have been struggling for over 5 hours now and I just don't know what to do anymore. I hope when someone sees my situation they can point me in the right direction. I think I've tried every single annotation combo and I can't get it to work.
I am setting up a Java EE application, simple web-app. Currently testing my setup in a simple page. The related files are below. The error occurs when pressing on the button on the xhtml page.
javax.el.PropertyNotFoundException: /greeting.xhtml @12,69 action="#{testServlet.createNewUser}": Target Unreachable, identifier 'testServlet' resolved to null
greeting.xhtml
<?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 xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Test Page</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value="Go"
action="#{testServlet.createNewUser}"/>
</h:form>
</h:body>
</html>
TestServlet.java
package kwetter.admin.test;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;
import kwetter.domain.entities.User;
import kwetter.logic.beans.TestBean;
@Named
@SessionScoped
public class TestServlet implements Serializable {
@Inject
private TestBean testBean;
public TestServlet() {
System.out.println("TEST CREATED ");
}
public String createNewUser() {
User user = new User();
testBean.createUser(user);
return "cool";
}
}
TestBean.java
package kwetter.logic.beans;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import kwetter.database.daos.interfaces.IUserDao;
import kwetter.domain.entities.User;
@Stateless
public class TestBean implements Serializable
{
@EJB
private IUserDao userDao;
public TestBean() {
}
public boolean createUser(User user) {
userDao.save(user);
return true;
}
}
IUserDao declaration
public interface IUserDao extends IDao<User>
And the implemenatation:
@Stateless
public class UserDao implements IUserDao
Dependencies of the different modules are handled in the pom files. Example part of the pom:
<dependency>
<groupId>com.woutervanacht.kwetter</groupId>
<artifactId>logic</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Other:
- I have an empty
beans.xml
in WEB-INF (not sure if this is needed anymore, started without and read it a couple of times faces-config.xml
which has no childs in the root elementweb.xml
with servlet mapping.
I don't want to clutter this question with too much information. If you need anything that is relevant I'll happily share.
Thanks in advance for thinking with me.