Reputation: 77
I'm trying to implement ViewScoped CDI bean using Omnifaces. Bean method that populates list with search results for primefaces datatable gets called using ajax from jsf page. If bean scope is set to session everything works correctly. When i try to set scope to Omnifaces ViewScope, container starts to create and destroy bean over and over many times without any reason. Here is the bean code:
...
import javax.inject.Named;
import org.omnifaces.cdi.ViewScoped;
@Named
@ViewScoped
public class FindClientBean implements Serializable {
@Inject
private ClientDAO clientDAO;
@NotNull(message="Search string cannot be empty")
private String searchString;
private List<Client> resultList;
@PostConstruct
public void init() {
System.out.println("init");
}
@PreDestroy
public void end() {
System.out.println("end");
}
public void findClient() {
System.out.println("method");
resultList = clientDAO.findClientByNameOrLastnamePart(searchString);
}
//Getters and setters..
}
Sample output (there are many more inits and ends for one method call, i skipped them):
01:51:50,044 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,044 INFO [stdout] (http-localhost-127.0.0.1-9090-4) init
01:51:50,044 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
01:51:50,045 INFO [stdout] (http-localhost-127.0.0.1-9090-4) end
01:51:50,045 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,045 INFO [stdout] (http-localhost-127.0.0.1-9090-4) init
01:51:50,046 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
01:51:50,046 INFO [stdout] (http-localhost-127.0.0.1-9090-4) method
01:51:50,047 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,047 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
01:51:50,048 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,048 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
01:51:50,049 INFO [stdout] (http-localhost-127.0.0.1-9090-5) init
01:51:50,049 INFO [stdout] (http-localhost-127.0.0.1-9090-5) end
What it can be? Haven't found relevant question. My configuration: JBoss AS 7.1, Omnifaces 1.6.3, Primefaces 4.0
Upvotes: 2
Views: 1059
Reputation: 11
I had the same problem. Reason it didnt work for me was, that in my Project Properties -> Project Facets was Dynamic Web Project of version 3.0
but in web.xml was project saved as 2.5
so I just changed 2.5 to 3.0 to look like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>zjazdi</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Upvotes: 1