2013-12-19 49 views
2

我想使用Omnifaces實現ViewScoped CDI bean。使用jsf頁面中的ajax調用用於填充primefaces數據表的搜索結果列表的Bean方法。如果將bean作用域設置爲會話,則一切正常。當我嘗試將範圍設置爲Omnifaces ViewScope時,容器開始無數次地反覆創建和銷燬bean。這裏是bean代碼:Omnifaces viewcoped bean被重新創建

... 
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..  

} 

樣本輸出(有更多inits和一個方法調用結束,我跳過它們):

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 

什麼可以嗎?沒有找到相關問題。 我的配置:JBoss AS 7.1,Omnifaces 1.6.3,Primefaces 4.0

+1

你在做客戶端操作? –

+1

究竟哪個AS 7.1顛覆? 7.1.0?因此,與Mojarra 2.1.5?而且,當您使用'javax.faces.bean'包中的'@ManagedBean @ ViewScoped'時,問題是否消失? – BalusC

+0

Alexandre:我試圖通過數據庫的ajax請求使用搜索字符串填充primefaces數據表。 – Cass

回答

1

我有同樣的問題。原因,它沒有工作對我來說是,在我的項目屬性 - >項目構面是版本3.0

動態Web項目,但在web.xml中的項目保存爲2.5

,所以我只是改變了2.5至3.0〜看起來像這樣:

<?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>