2013-04-09 51 views
1

我有一個帶有primefaces 3.5的JSF 2.2.0-m12應用程序。由於我將應用程序從JBoss 7.1.1移植到Tomcat 7.0.39,重新加載頁面後輸入字段(輸入文本,滑塊,按鈕......)的第一次更改工作正常,但第二次更改沒有任何作用。我搜索所述第一和第二請求之間的差異:沒有發送ViewState

第一請求:

  • JSF階段:階段1至6被執行
  • 在螢火蟲「網絡 - >所有 - > POST zinsrechner.xhtml - >交的」是一個視圖狀態:
 
contentForm contentForm 
contentForm:inputZinsatz  2.0 
contentForm:j_idt157:anla... 277 
contentForm:j_idt157:maxA... 25 
contentForm:j_idt157:slid... 277 
contentForm:j_idt72:saveA... 10000 
contentForm:j_idt72:saveA... 20000 
contentForm:selectSparArt  false 
javax.faces.ViewState  -1622287370124327744:4775655032591022279 
javax.faces.behavior.even... slideEnd 
javax.faces.partial.ajax  true 
javax.faces.partial.event  slideEnd 
javax.faces.partial.execu... contentForm:j_idt157:sliderAnlageDauer 
javax.faces.partial.rende... contentForm 
javax.faces.source    contentForm:j_idt157:sliderAnlageDauer 

第二請求:

  • JSF階段:在執行6 1階段之後
  • 在螢火蟲 '網絡 - >所有 - > POST zinsrechner.xhtml - >交的' 是沒有視圖狀態:
 
contentForm contentForm 
contentForm:inputZinsatz  2.0 
contentForm:j_idt157:anla... 460 
contentForm:j_idt157:maxA... 25 
contentForm:j_idt157:slid... 460 
contentForm:j_idt72:saveA... 10000 
contentForm:j_idt72:saveA... 20000 
contentForm:selectSparArt  false 
javax.faces.behavior.even... slideEnd 
javax.faces.partial.ajax  true 
javax.faces.partial.event  slideEnd 
javax.faces.partial.execu... contentForm:j_idt157:sliderAnlageDauer 
javax.faces.partial.rende... contentForm 
javax.faces.source    contentForm:j_idt157:sliderAnlageDauer 

現在我不確定,如果缺少ViewState導致不正確的行爲。

在我的頁面中有三個不包含表單。對於每一個的形式是在outcoming HTML格式呈現一個隱藏的視圖狀態標記(冷凝):

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title>Zinsrechner</title> 
<body> 
<div class="wrapper"> 
    <form id="headerForm" name="headerForm" method="post" 
     action="/Tools_Web/pages/rechner/zinsrechner.xhtml" 
     enctype="application/x-www-form-urlencoded"> 
     <input type="hidden" name="headerForm" value="headerForm" /> 

     <header> 
      <html xmlns="http://www.w3.org/1999/xhtml"> 
       <script type="text/javascript"> ... </script> 
       <nav>...</nav> 
      </html> 
      <h1>Zinsrechner</h1> 
     </header> 
     <input type="hidden" name="javax.faces.ViewState" 
      id="j_id1:javax.faces.ViewState:0" 
      value="863948539220421748:307506195687956782" autocomplete="off" /> 
    </form> 


    <div id="contentOutline"> 
     <div id="content"> 
      <div class="wrapper"> 
       <form id="contentForm" name="contentForm" method="post" 
        action="/Tools_Web/pages/rechner/zinsrechner.xhtml" 
        enctype="application/x-www-form-urlencoded"> 
        <input type="hidden" name="contentForm" value="contentForm" /> 
        <div id="sidebar"></div> 
        <div id="zinsrechner"> 
         <!-- Headline --> 
         <header> 
          <div style="padding: 0 1em; float: right;"> 
           <span 
            title="Zinssatz pro Jahr"><span id="contentForm:j_idt70" 
            class="ui-inplace ui-hidden-container"><span 
             id="contentForm:j_idt70_display" class="ui-inplace-display" 
             style="display: inline">2.0%</span><span 
             id="contentForm:j_idt70_content" class="ui-inplace-content" 
             style="display: none"><input 
              id="contentForm:inputZinsatz" name="contentForm:inputZinsatz" 
              type="text" value="2.0" 
              style="width: 70px; right: 0px; top: 0 position:absolute" 
              class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all" /> 
             <script id="contentForm:inputZinsatz_s" type="text/javascript">PrimeFaces.cw('InputText','widget_contentForm_inputZinsatz',{id:'contentForm:inputZinsatz',behaviors:{change:function(event) {mojarra.ab('contentForm:inputZinsatz',event,'valueChange','@form','@form headerForm footerForm')},change:function(event) {PrimeFaces.ab({source:'contentForm:inputZinsatz',event:'change',process:'contentForm:inputZinsatz',update:'contentForm'}, arguments[1]);}}});</script></span></span> 
           <script id="contentForm:j_idt70_s" type="text/javascript">PrimeFaces.cw('Inplace','widget_contentForm_j_idt70',{id:'contentForm:j_idt70',effect:'fade',effectSpeed:'normal',event:'click',toggleable:true});</script> 
           </span> 
          </div> 
         </header> 


         <div> 
          <!-- More input elements --> 
         </div> 
        </div> 
        <input type="hidden" name="javax.faces.ViewState" 
         id="j_id1:javax.faces.ViewState:0" 
         value="863948539220421748:307506195687956782" autocomplete="off" /> 
       </form> 
      </div> 
     </div> 
    </div> 
    <form id="footerForm" name="footerForm" method="post" 
     action="/Tools_Web/pages/rechner/zinsrechner.xhtml" 
     enctype="application/x-www-form-urlencoded"> 

     <input type="hidden" name="footerForm" value="footerForm" /> 

     <footer></footer> 
     <input type="hidden" name="javax.faces.ViewState" 
      id="j_id1:javax.faces.ViewState:0" 
      value="863948539220421748:307506195687956782" autocomplete="off" /> 
    </form> 
</div> 

我企圖未能成功與這裏描述的JS解決問題: h:commandButton/h:commandLink does not work on first click, works only on second click

和以下配置在web.xml中:

<context-param> 
<param-name>com.sun.faces.autoCompleteOffOnViewState</param-name> 
<param-value>false</param-value> 
</context-param> 

<context-param> 
<param-name>com.sun.faces.enableViewStateIdRendering</param-name> 
<param-value>false</param-value> 
</context-param> 

編輯 這是XHTML頁面:

<ui:composition 
xmlns="http://www.w3.org/1999/xhtml" 
xmlns:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:p="http://primefaces.org/ui" 
template="/template/baseLayout.xhtml" 
xmlns:ad="http://java.sun.com/jsf/composite/components/ad"> 
<ui:param 
    name="title" 
    value="Zinsrechner" /> 
<ui:param 
    name="bgClass" 
    value="whiteGrid" /> 
<ui:define name="content"> 
    <div id="zinsrechner"> 
     <!-- Headline --> 
     <header> 
      <p:selectOneButton 
       id="selectSparArt" 
       value="#{zinsrechner.monthly}" 
       styleClass="selectSparArt"> 
       <f:selectItem 
        itemLabel="Anlagebetrag" 
        itemValue="#{false}" /> 
       <f:selectItem 
        itemLabel="Sparbetrag" 
        itemValue="#{true}" /> 
       <p:ajax 
        event="change" 
        update="contentForm" 
        process="selectSparArt" 
        listener="#{zinsrechner.onMonthlyChange()}" /> 
      </p:selectOneButton> 
      <div style="padding: 0 1em; float: right;"> 
       <span title="Monatlicher Sparbetrag"> 
        <p:inplace label="#{zinsrechner.saveAmount}€" rendered="#{zinsrechner.monthly}"> 
         <p:inputText 
          style="width: 70px; margin-right: 10px;" 
          id="inputSparbetrag" 
          value="#{zinsrechner.saveAmount}"> 
          <p:ajax 
           event="change" 
           update="contentForm" 
           process="inputSparbetrag" 
           listener="#{zinsrechner.onSaveAmountChange()}" /> 
          </p:inputText> 
         </p:inplace> 
        </span> 

       <span title="Zinssatz pro Jahr"> 
        <p:inplace label="#{zinsrechner.interestRate}%"> 
         <p:inputText 
          style="width: 70px; right:0px; top: 0 position:absolute" 
          id="inputZinsatz" 
          value="#{zinsrechner.interestRate}"> 
          <p:ajax 
           event="change" 
           update="contentForm" 
           process="inputZinsatz" 
           listener="#{zinsrechner.onInterestRateChange()}" /> 
           <f:ajax execute="@form" render="@form :headerForm :footerForm"></f:ajax> 
         </p:inputText> 
        </p:inplace> 
       </span> 
      </div> 
     </header> 

     <!-- Y-Achse --> 
     <ad:yAxis 
      component="#{zinsrechner}" 
      editable="true" 
      inputId="saveAmount" 
      inputMaxValueId="saveAmountMax" 
      rendered="true" 
      sliderId="saveAmountSlider"></ad:yAxis> 

     <!-- Chartcontainer --> 
     <ad:barChart 
      component="#{zinsrechner}" 
      rendered="true" 
      renderSumBarLeft="false" 
      renderSumBarRight="false" /> 


     <!-- X-Achse --> 
     <ad:xAxis 
      component="#{zinsrechner}" 
      sliderId="sliderAnlageDauer" 
      editable="true" 
      inputId="anlagedauer" 
      inputMaxValueId="maxAnlagedauer" 
      rendered="true" 
      renderSumBarLeft="false" 
      renderSumBarRight="false"></ad:xAxis> 
    </div> 
</ui:define> 

我能做些什麼的ViewStatus傳遞到服務器?缺少的ViewState可能是不正確行爲的原因嗎?

感謝您的幫助。如果您需要更多信息,只需詢問!

+0

也許你應該添加源代碼 - 你使用的xhtml和primefaces組件。如果「重新加載頁面後」有效,但在此之後它停止工作,聽起來很像一個JavaScript事件處理程序丟失。 – Jens 2013-04-09 11:22:19

+0

@Jens:感謝您的評論。我添加了xhtml頁面。 – Karina 2013-04-09 11:28:02

+2

PF 3.5不是爲JSF 2.2設計的。你應該使用PF 4.0。請使用常規JSF組件測試以排除PF 3.5的原因,或者降級到JSF 2.1。順便說一句,在單個輸入組件中同時使用''和''看起來不正確。 – BalusC 2013-04-09 11:55:48

回答

2

像BalusC和Jens說,這個問題是Primefaces和JSF的版本:

PF 3.5不適用於JSF 2.2。你應該使用PF 4.0。請使用常規JSF組件測試以排除PF 3.5的原因,或者降級到JSF 2.1。

降級到JSF 2.1之後,它可以工作。