开发者

javascript popup does not get managed value

开发者 https://www.devze.com 2023-02-02 22:14 出处:网络
I do not understand that when I press save in the form below I save the current contents of the inputTextArea, but when I want to look at a preview of the contents of inputTextArea I see the contents

I do not understand that when I press save in the form below I save the current contents of the inputTextArea, but when I want to look at a preview of the contents of inputTextArea I see the contents of the last saved mail template. What I should see is of course the current value of the textArea (after it is converted). Why does it not show the updated value of 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}"
   开发者_C百科               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()%>

Is something maybe wrong about the timing?

By the way game doNothing is really doing nothing. It is an empty void method.


The problem is that the second command button has its immediate attribute set to true. This will cause the action method to be invoked in the apply request values phase, and thereafter skip immediately to render response.

In effect, no model values will be updated, thus you keep having the previous values in the model. Confusingly maybe, but the component will retain the value you just entered. I just didn't transfer to the model. For more information about this look up what the immediate attribute means in JSF and especially what it does when applied to a command button.

(I also would like to remark that using the session scope to communicate values to a popup is asking for trouble. This opens the door to all kinds of race conditions when the user has the page opened in multiple tabs or windows. If possible, you might be better off using Java EE 6's conversation scope.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号