Jsf 如何使用@ViewScoped对每个ajax请求激发方法
我使用JSF2.2,我必须对我在@Named@viewScoped中使用@PostConstruct的每个ajax请求调用方法,但它在我第一次调用bean时触发,但在那之后不会触发,因为我使用@viewScoped,所以您能给我一种方法来对每个ajax请求调用方法吗Jsf 如何使用@ViewScoped对每个ajax请求激发方法,jsf,Jsf,我使用JSF2.2,我必须对我在@Named@viewScoped中使用@PostConstruct的每个ajax请求调用方法,但它在我第一次调用bean时触发,但在那之后不会触发,因为我使用@viewScoped,所以您能给我一种方法来对每个ajax请求调用方法吗 import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.inject.Named; import javax.faces.view.View
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.inject.Named;
import javax.faces.view.ViewScoped;
@Named(value = "branchesMB")
@ViewScoped
public class BranchesController extends CRUDController<Branches> implements Serializable {
@EJB
private BranchesFacade branchesFacade;
private List<String> jsfMessages = new ArrayList<>();
/**
* Creates a new instance of BranchesController
*/
public BranchesController() {
setEntityObject(new Branches());
setEntityEditObject(new Branches());
}
@PostConstruct
public void init() {
JsfUtil.resetValidationError(true, "branchesAddForm:branchNameDiv");
JsfUtil.resetValidationError(true, "branchesAddForm:branchAddressDiv");
JsfUtil.resetValidationError(true, "branchesAddForm:branchAbbreviationDiv");
JsfUtil.hideAlertMessage("branchesForm:messages");
JsfUtil.hideAlertMessage("branchesAddForm:messages");
// System.out.println("koko");
}
}
import javax.annotation.PostConstruct;
导入javax.ejb.ejb;
导入javax.inject.Named;
导入javax.faces.view.ViewScoped;
@命名(value=“branchesMB”)
@视域
公共类BranchesController扩展CRUDController实现可序列化{
@EJB
私人分行门面分行门面;
private List jsfMessages=new ArrayList();
/**
*创建BranchesController的新实例
*/
公共分公司财务总监(){
setEntityObject(新分支());
setEntityEditObject(新分支());
}
@施工后
公共void init(){
resetValidationError(true,“branchesAddForm:branchNameDiv”);
resetValidationError(true,“branchesAddForm:branchAddressDiv”);
resetValidationError(true,“branchesAddForm:branchabreviationdiv”);
JsfUtil.hideAlertMessage(“branchesForm:messages”);
JsfUtil.hideAlertMessage(“branchesAddForm:messages”);
//System.out.println(“koko”);
}
}
您可以创建一个以CompositeSystemEvent作为输入参数的方法,并在xhtml上的事件标记中定义该方法,类型为“preRenderView”,如下所示:
在支持bean上:
public void onPageLoad(ComponentSystemEvent event) {
System.out.println("Here");
}
在xhtml页面上:
<f:event listener="#{bean.onPageLoad}" type="preRenderView"></f:event>
每次加载完整页面之前和每次调用ajax时,都会调用此方法。为什么不使用RequestScope?因为当我使用delete方法时,会删除另一行,两个用户同时删除一些内容。我想首先调用此方法,在调用ajax方法的末尾调用此方法在第一线进行后期施工。