2014-09-26 3 views
0

CDI ViewScoped 빈과 JSF 페이지가 있습니다. 몇 가지 AJAX 요청 후에 빈은 어떻게 든 재현됩니다. 다음은 응용 프로그램의 전체 코드입니다 : QuestionBean.java일부 AJAX 요청 후에 ViewScoped CDI Bean이 다시 생성되었습니다.

기가 CDI 빈

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> 

됩니다

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

글래스 피쉬 - 글쇠 javax.faces.jar을 here에서 업데이트 한 후 저에게 도움이되었습니다. 가장 최신의 2.2.8-02를 가져 와서 글래스 피시/글래스 피시/모듈로 대체했습니다.

오류가 수정되었거나 정확히 해결되지 않은 것을 알 수 없습니다.

희망 사항은 귀하에게도 적합합니다.

+0

시간 내 주셔서 감사합니다. –