2014-09-26 42 views
0

我有一个CDI ViewScoped bean和一个JSF页面。在几个AJAX请求之后,豆以某种方式重新创建。 这里是应用程序的全码:ViewScoped在一些AJAX请求后重新创建CDI bean

的index.xhtml

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:h="http://xmlns.jcp.org/jsf/html" 
     xmlns:f="http://java.sun.com/jsf/core" 
     xmlns:ui="http://xmlns.jcp.org/jsf/facelets"> 
    <h:head> 
     <title>Facelet Title</title> 
    </h:head> 
    <h:body> 
     Hello from Facelets 
     <h:form> 
      <h:inputText value="#{questionBean.newTag}"></h:inputText> 
      <h:commandButton value="Add Tag"> 
       <f:ajax listener="#{questionBean.addTag()}" execute="@form" render="@form"></f:ajax> 
      </h:commandButton> 
      <ui:repeat value="#{questionBean.tagsOfQuestion}" var="tag"> 
       <h:outputLabel value="#{tag}"></h:outputLabel> 
       <h:commandButton value="X"> 
        <f:ajax event="click" listener="#{questionBean.removeTag(tag)}" render="@form" execute="@form"/> 
       </h:commandButton> 
      </ui:repeat> 
     </h:form> 
    </h:body> 
</html> 

这里是后盾CDI豆 QuestionBean.java

import java.util.ArrayList; 
    import java.util.Date; 
    import java.util.List; 
    import javax.faces.view.ViewScoped; 
    import javax.inject.Named; 

    @Named 
    @ViewScoped  
    public class QuestionBean { 
     private String newTag; 
     private List<String> tagsOfQuestion = new ArrayList<String>(); 
     private Date dateCreated = new Date(); 

    public QuestionBean(){ 
     System.out.println("Date Created : "+dateCreated); 
    } 

    public void addTag(){ 
     if(!newTag.isEmpty()){ 
      getTagsOfQuestion().add(newTag); 
     } 
     newTag = ""; 
    } 

    public void removeTag(String tagToRemove){ 
     getTagsOfQuestion().remove(tagToRemove); 
    } 

    public String getNewTag() { 
     return newTag; 
    } 

    public void setNewTag(String newTag) { 
     this.newTag = newTag; 
    } 

    public List<String> getTagsOfQuestion() { 
     return tagsOfQuestion; 
    } 

    public void setTagsOfQuestion(List<String> tagsOfQuestion) { 
     this.tagsOfQuestion = tagsOfQuestion; 
    } 

} 

回答

2

嗯,我有同样的问题,当我试图它 - Netbeans 8和JSF 2.2.0也是如此。

我更新后为我工作Glassfish - 从here抓取javax.faces.jar - 我使用了最新的2.2.8-02,并替换了glassfish/glassfish/modules中的一个。

不知道错误是什么,或者确切地说它是固定的。

希望它也适用于你。

+0

谢谢你的时间。 – 2014-09-28 09:21:40

相关问题