我不明白,当我在下面的表单中按保存时,我保存了 inputTextArea 的当前内容,但是当我想查看 inputTextArea 的内容预览时,我看到了上次保存的邮件模板的内容。我应该看到的当然是 textArea 的当前值(转换后)。为什么不显示 customMailTemplate 的更新值?
<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”实际上就是什么都不做。这是一个空的 void 方法。
最佳答案
问题在于第二个命令按钮的立即属性设置为 true。这将导致在应用请求值阶段调用操作方法,然后立即跳过以渲染响应。
实际上,不会更新任何模型值,因此模型中会保留以前的值。也许令人困惑,但该组件将保留您刚刚输入的值。我只是没有转行做模特而已。有关此内容的更多信息,请查看即时属性在 JSF 中的含义,尤其是它在应用于命令按钮时的作用。
(我还想指出,使用 session 范围向弹出窗口传递值是自找麻烦。当用户在多个选项卡中打开页面或windows。如果可能,您最好使用 Java EE 6 的对话范围。)
关于javascript 弹出窗口未获取托管值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4630799/