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;
}
}
시간 내 주셔서 감사합니다. –