这似乎不对.我正在清理我的代码,我只是注意到了这一点.每个ajax请求都会触发构造函数和@PostConstruct我的@ViewScopedbean.即使是简单的数据库分页也会触发它.
我知道这@ViewScoped比@RequestScoped任何请求都要重建并且不应该重建.只有在通过GET重新加载完整页面之后.
我有以下页面:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html">
<body>
<ui:composition template="./templates/fireLeftMenuTemplate.xhtml">
<ui:define name="left">
<h:form>
<p:menu model="#{gradingBean.courseMenu}"/>
</h:form>
</ui:define>
<ui:define name="content">
<h:form>
<p:accordionPanel binding="#{gradingBean.assignmentView}"/>
</h:form>
</ui:define>
</ui:composition>
</body>
Run Code Online (Sandbox Code Playgroud)
GradingBean:
@Named("gradingBean")
@ViewScoped
public class GradingBean {
@EJB
private AssignmentManager assignmentManager;
/*
* The assignmentMenu, listing all assignments for each course currently
* assisted by this grader
*/
private final DefaultMenuModel courseView = new DefaultMenuModel();
private final AccordionPanel assignmentView = new AccordionPanel();
public …Run Code Online (Sandbox Code Playgroud)