Primefaces民意调查导致其他形式过期

时间:2016-10-24 01:28:07

标签: primefaces jsf-2

我有两页jsf。 dashboard.xhtml有一个<p:poll />标记,每秒更新一次“form1”,而input.xhtml只是一个基本的crud页面,用于更新dashboard.xhtml中的显示。我想知道,因为当dashboard.xhtml在不同的标签页或浏览器的第二个窗口中打开时,input.xhtml会一直失去其状态并导致视图过期ViewExpiredException。当我尝试将<o:enableRestorableView />放在template_2.xhtml中时,ViewExpiredException消失了,但是当我提交表单时我的输入值正在重置。当dashboard.xhtml未打开时,不会重置。当它打开时,输入随机重置。

我想要完成的是当我在input.xhtml中输入一些数据时,我希望它实时显示在dashboard.xhtml中。没有(ViewExpiredException),有人知道如何做到这一点吗?该应用程序在WebSphere 8.5(MyFaces 2.0),Primefaces 6.0,OmniFaces 1.8.3中运行

dashboard.xhtml:

     <ui:composition template="/WEB-INF/template_1.xhtml"
            xmlns:p="http://primefaces.org/ui"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:o="http://omnifaces.org/ui">
        <ui:define name="content">
            <h:form id="form1">
               <p:poll interval="1" listener="#{dashboardBacking.updateValues}" update="form1"
                        global="false" />

               <!-- dashboard content -->
            </h:form>
         </ui:define>
        </ui:composition>

input.xhtml:

<ui:composition template="/WEB-INF/template_2.xhtml"
    xmlns:p="http://primefaces.org/ui"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:o="http://omnifaces.org/ui">
 <ui:define name="content">
    <h:form id="form2">

       <p:panelGrid>
          <p:row>
            <p:column>
              <p:inputText value="#{inputBacking.values.description}" />
            </p:column>
          </p:row>
          <p:row>
            <p:column>
              <p:commandButton id="#{inputBacking.save}" update="form2"/>
            </p:column>
          </p:row>
       </p:panelGrid>
    </h:form>
 </ui:define>
</ui:composition>

Backing bean(dashboard.xhtml):

@ManagedBean
@ViewScoped
public class DashboardBacking {
   @EJB
   private Dashboard dashboard;

   private DashboardValues values;

   @PostConstruct
   public void postConstruct(){
        values = new DashboardValues();
        updateValues();
   }

   public void updateValues(){
     DashboardValues newValues = dashboard.getValue();
     if(!newValues.exactlyEqual(values)){
        values = newValues;
     }

   }

   public DashboardValues getValues(){
       return values;
   }
}

支持bean(input.xhtml):

@ManagedBean
@ViewScoped
public class InputBacking {

   @EJB
   private DashboardDao dao;

   private DashboardValues values;

   public void save(){
     dao.save(values)
   }

   //Getters and Setters
}

仪表板单件类:

@Singleton
@Startup
public class Dashboard {
   @EJB
   private DashboardDao dao;

   private DashboardValue value;

   @Schedule(second="*/5") //update dashboard value every 5 seconds
   private void updater(){
    value = dao.getLatest();
   }

   public DashvoardValue getValue(){
      return value;
   }
}

template_1.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
    xmlns:of="http://omnifaces.org/functions">
<f:view contentType="text/html">
    <f:metadata>
        <o:enableRestorableView  />
    </f:metadata>
    <h:head>
    </h:head>
    <h:body>
      <ui:insert name="content"/>
    </h:body>
</f:view>
</html>

template_2.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
    xmlns:of="http://omnifaces.org/functions">
<f:view contentType="text/html">
    <h:head>
    </h:head>
    <h:body>
      <ui:insert name="content"/>
    </h:body>
</f:view>
</html>

0 个答案:

没有答案