2011-01-07 34 views
0

我不明白,當我按下下面的表格保存時,我保存了inputTextArea的當前內容,但是當我想查看inputTextArea內容的預覽時,我看到內容最後一次保存的郵件模板。我應該看到的當然是textArea的當前值(轉換後)。爲什麼它不顯示customMailTemplate的更新值?javascript popup沒有管理值

<h:form id="gameMailForm" prependId="false" rendered="#{customizeGameMailBean.renderGameMailPanel}"> 
     <h:panelGrid columns="3"> 
     <h:inputTextarea 
       styleClass="gameMailTextArea, textArea" 
       id="gameMailTextArea" 
       value="#{customizeGameMailBean.customMailTemplate}" 
       converter="gameMailTemplateConverter" 
       style="height: 120px; width: 300px; font-size: 11px;"> 
       <f:validator validatorId="gameMailValidator"/> 
     </h:inputTextarea> 
<p:commandButton value="Save" 
        action="#{customizeGameMailBean.saveMailTemplate}" 
        ajax="false"/> 
<p:commandButton value="Preview" 
        ajax="true" 
        action="#{customizeGameMailBean.doNothing}" 
        oncomplete="javascript: window.open('gameMailPreview.jsp','Game Email','width=300,height=300')" 
        immediate="true"/> 
</h:panelGrid> 
</h:form> 

gameMailPreview.jsp:

<%@page import="wmc.web.controller.CustomizeGameMailBean"%> 
<%@page import="javax.faces.context.FacesContext"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<% CustomizeGameMailBean gameMailBean = (CustomizeGameMailBean) request.getSession().getAttribute("customizeGameMailBean");%> 
<%=gameMailBean.getCustomMailPreview()%> 

是什麼也許錯了時間?

順便說一句遊戲doNothing真的什麼都不做。這是一個空洞的無效方法。

+0

Eek,爲什麼'gameMailPreview.jsp`不是JSF頁面? – BalusC 2011-01-07 22:21:00

+0

這是因爲customMailPreview是html代碼。我不知道如何在這樣的jsf頁面中放入html。 – AnAmuser 2011-01-07 22:24:14

回答

1

問題是第二個命令按鈕的立即屬性設置爲true。這將導致在應用請求值階段調用操作方法,然後立即跳過以呈現響應。

實際上,沒有模型值將被更新,因此您在模型中保留了以前的值。可能會感到困惑,但組件會保留剛輸入的值。我只是沒有轉移到模型。有關此更多信息,請查看JSF中immediate屬性的含義,特別是它應用於命令按鈕時的作用。 (我也想指出,使用會話範圍來向彈出窗口傳遞值需要麻煩,當用戶在多個選項卡或窗口中打開頁面時,這爲各種競爭條件打開了大門。如果可能的話,使用Java EE 6的對話範圍可能會更好。)