Index: core/src/main/java/org/icefaces/impl/event/FormSubmit.java =================================================================== --- core/src/main/java/org/icefaces/impl/event/FormSubmit.java (revision 24095) +++ core/src/main/java/org/icefaces/impl/event/FormSubmit.java (working copy) @@ -31,103 +31,107 @@ import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import javax.faces.event.AbortProcessingException; +import javax.faces.event.PhaseId; import javax.faces.event.PostAddToViewEvent; import javax.faces.event.SystemEvent; import javax.faces.event.SystemEventListener; import java.io.IOException; public class FormSubmit implements SystemEventListener { - public static final String DISABLE_CAPTURE_SUBMIT = "DISABLE_CAPTURE_SUBMIT"; - private static final String CAPTURE_SUBMIT_SUFFIX = "_captureSubmit"; - private boolean deltaSubmit; - private boolean partialStateSaving; + public static final String DISABLE_CAPTURE_SUBMIT = "DISABLE_CAPTURE_SUBMIT"; + private static final String CAPTURE_SUBMIT_SUFFIX = "_captureSubmit"; + private static final String ADDED_CAPTURESUBMIT = "org.icefaces.events."+CAPTURE_SUBMIT_SUFFIX; + private boolean deltaSubmit; + private boolean partialStateSaving; - public FormSubmit() { - FacesContext facesContext = FacesContext.getCurrentInstance(); - deltaSubmit = EnvUtils.isDeltaSubmit(facesContext); - partialStateSaving = EnvUtils.isPartialStateSaving(facesContext); - } + public FormSubmit() { + FacesContext facesContext = FacesContext.getCurrentInstance(); + deltaSubmit = EnvUtils.isDeltaSubmit(facesContext); + partialStateSaving = EnvUtils.isPartialStateSaving(facesContext); + } - public void processEvent(SystemEvent event) throws AbortProcessingException { - FacesContext context = FacesContext.getCurrentInstance(); - if (!EnvUtils.isICEfacesView(context)) { - return; - } + public void processEvent(SystemEvent event) throws AbortProcessingException { + FacesContext context = FacesContext.getCurrentInstance(); + if (!EnvUtils.isICEfacesView(context) || context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) { + return; + } - //using PostAddToViewEvent ensures that the component resource is added to the view only once - final HtmlForm form = (HtmlForm) ((PostAddToViewEvent) event).getComponent(); - if (form.getAttributes().get(DISABLE_CAPTURE_SUBMIT) != null) { - return; - } - String componentId = form.getId() + CAPTURE_SUBMIT_SUFFIX; + // using PostAddToViewEvent ensures that the component resource is added to the view only once + final HtmlForm form = (HtmlForm) ((PostAddToViewEvent) event).getComponent(); + if (form.getAttributes().get(DISABLE_CAPTURE_SUBMIT) != null + || form.getAttributes().containsKey(ADDED_CAPTURESUBMIT)) { + return; + } + String componentId = form.getId() + CAPTURE_SUBMIT_SUFFIX; - if (!partialStateSaving) { - for (UIComponent child : form.getChildren()) { - String id = child.getId(); - if ((null != id) && id.endsWith(CAPTURE_SUBMIT_SUFFIX)) { - return; - } - } - } + if (!partialStateSaving) { + for (UIComponent child : form.getChildren()) { + String id = child.getId(); + if ((null != id) && id.endsWith(CAPTURE_SUBMIT_SUFFIX)) { + return; + } + } + } + + UIOutput scriptWriter = new UIOutputWriter() { + public void encode(ResponseWriter writer, FacesContext context) throws IOException { + if (form.getAttributes().get(DISABLE_CAPTURE_SUBMIT) != null) { + return; + } + String formId = form.getClientId(context); + writer.startElement("script", this); + writer.writeAttribute("type", "text/javascript", "type"); + writer.writeAttribute("id", getClientId(context), "id"); + writer.write("ice.captureSubmit('"); + writer.write(formId); + writer.write("',"); + writer.write(Boolean.toString(deltaSubmit)); + writer.write(");"); + writer.write("ice.captureEnterKey('"); + writer.write(formId); + writer.write("');"); + writer.endElement("script"); + } + }; - UIOutput scriptWriter = new UIOutputWriter() { - public void encode(ResponseWriter writer, FacesContext context) throws IOException { - if (form.getAttributes().get(DISABLE_CAPTURE_SUBMIT) != null) { - return; - } - String formId = form.getClientId(context); - writer.startElement("script", this); - writer.writeAttribute("type", "text/javascript", "type"); - writer.writeAttribute("id", getClientId(context), "id"); - writer.write("ice.captureSubmit('"); - writer.write(formId); - writer.write("',"); - writer.write(Boolean.toString(deltaSubmit)); - writer.write(");"); - writer.write("ice.captureEnterKey('"); - writer.write(formId); - writer.write("');"); - writer.endElement("script"); - } - }; + scriptWriter.setId(componentId); + scriptWriter.setTransient(true); + form.getChildren().add(0, scriptWriter); - scriptWriter.setId(componentId); - scriptWriter.setTransient(true); - form.getChildren().add(0, scriptWriter); + AjaxDisabledWriter disabledWriter = new AjaxDisabledWriter(); + disabledWriter.setTransient(true); + //add to end of list + form.getAttributes().put(ADDED_CAPTURESUBMIT, true); + form.getChildren().add(disabledWriter); - AjaxDisabledWriter disabledWriter = new AjaxDisabledWriter(); - disabledWriter.setTransient(true); - //add to end of list - form.getChildren().add(disabledWriter); + } - } - - public boolean isListenerForSource(Object source) { - return source instanceof HtmlForm; - } + public boolean isListenerForSource(Object source) { + return source instanceof HtmlForm; + } } class AjaxDisabledWriter extends UIOutputWriter { - public void encode(ResponseWriter writer, FacesContext context) - throws IOException { - UIForm form = AjaxDisabledList.getContainingForm(this); - //consume with remove to reset the list each time - String value = (String) form.getAttributes() - .remove(AjaxDisabledList.DISABLED_LIST); - if (null == value) { - return; - } - writer.startElement("input", this); - writer.writeAttribute("type", "hidden", "type"); - writer.writeAttribute("id", getClientId(context), "id"); - writer.writeAttribute("disabled", "true", "disabled"); - writer.writeAttribute("value", value, "value"); - writer.endElement("input"); - } + public void encode(ResponseWriter writer, FacesContext context) + throws IOException { + UIForm form = AjaxDisabledList.getContainingForm(this); + //consume with remove to reset the list each time + String value = (String) form.getAttributes() + .remove(AjaxDisabledList.DISABLED_LIST); + if (null == value) { + return; + } + writer.startElement("input", this); + writer.writeAttribute("type", "hidden", "type"); + writer.writeAttribute("id", getClientId(context), "id"); + writer.writeAttribute("disabled", "true", "disabled"); + writer.writeAttribute("value", value, "value"); + writer.endElement("input"); + } - public String getClientId(FacesContext context) { - UIForm form = AjaxDisabledList.getContainingForm(this); - return (form.getClientId() + UINamingContainer - .getSeparatorChar(context)+ "ajaxDisabled"); - } + public String getClientId(FacesContext context) { + UIForm form = AjaxDisabledList.getContainingForm(this); + return (form.getClientId() + UINamingContainer + .getSeparatorChar(context)+ "ajaxDisabled"); + } } Index: core/src/main/java/org/icefaces/impl/event/WindowAndViewIDSetup.java =================================================================== --- core/src/main/java/org/icefaces/impl/event/WindowAndViewIDSetup.java (revision 24095) +++ core/src/main/java/org/icefaces/impl/event/WindowAndViewIDSetup.java (working copy) @@ -30,6 +30,7 @@ import javax.faces.context.FacesContext; import javax.faces.context.ResponseWriter; import javax.faces.event.AbortProcessingException; +import javax.faces.event.PhaseId; import javax.faces.event.PostAddToViewEvent; import javax.faces.event.SystemEvent; import javax.faces.event.SystemEventListener; @@ -38,67 +39,73 @@ import java.util.logging.Logger; public class WindowAndViewIDSetup implements SystemEventListener { - private static final Logger Log = Logger.getLogger(WindowAndViewIDSetup.class.getName()); - private static final String ID_SUFFIX = "_windowviewid"; - private boolean partialStateSaving; + private static final Logger Log = Logger.getLogger(WindowAndViewIDSetup.class.getName()); + private static final String ID_SUFFIX = "_windowviewid"; + private static final String ADDED_WINDOWANDVIEWID = "org.icefaces.events."+ID_SUFFIX; + private boolean partialStateSaving; - public WindowAndViewIDSetup() { - partialStateSaving = EnvUtils.isPartialStateSaving( - FacesContext.getCurrentInstance() ); - } + public WindowAndViewIDSetup() { + partialStateSaving = EnvUtils.isPartialStateSaving( + FacesContext.getCurrentInstance() ); + } - public void processEvent(SystemEvent event) throws AbortProcessingException { - final FacesContext context = FacesContext.getCurrentInstance(); - if (!EnvUtils.isICEfacesView(context)) { - return; - } + public void processEvent(SystemEvent event) throws AbortProcessingException { + final FacesContext context = FacesContext.getCurrentInstance(); + if (!EnvUtils.isICEfacesView(context)) { + return; + } - HtmlForm form = (HtmlForm) ((PostAddToViewEvent) event).getComponent(); - String componentId = form.getId() + ID_SUFFIX; + HtmlForm form = (HtmlForm) ((PostAddToViewEvent) event).getComponent(); + String componentId = form.getId() + ID_SUFFIX; - if (!partialStateSaving) { - for (UIComponent child : form.getChildren()) { - String id = child.getId(); - if ((null != id) && id.endsWith(ID_SUFFIX)) { - return; - } - } - } + if (form.getAttributes().containsKey(ADDED_WINDOWANDVIEWID)) { + return; + } + + if (!partialStateSaving) { + for (UIComponent child : form.getChildren()) { + String id = child.getId(); + if ((null != id) && id.endsWith(ID_SUFFIX)) { + return; + } + } + } + + UIOutput output = new UIOutputWriter() { + public void encode(ResponseWriter writer, FacesContext context) throws IOException { + Map requestMap = context.getExternalContext().getRequestMap(); - UIOutput output = new UIOutputWriter() { - public void encode(ResponseWriter writer, FacesContext context) throws IOException { - Map requestMap = context.getExternalContext().getRequestMap(); + if (WindowScopeManager.lookupAssociatedWindowID(requestMap) == null) { + Log.severe("Missing window ID attribute. Request map cleared prematurely."); + return; + } + String viewId = BridgeSetup.getViewID(context.getExternalContext()); + if (viewId == null) { + Log.severe("Missing view ID attribute. Request map cleared prematurely."); + return; + } - if (WindowScopeManager.lookupAssociatedWindowID(requestMap) == null) { - Log.severe("Missing window ID attribute. Request map cleared prematurely."); - return; - } - String viewId = BridgeSetup.getViewID(context.getExternalContext()); - if (viewId == null) { - Log.severe("Missing view ID attribute. Request map cleared prematurely."); - return; - } + writer.startElement("input", this); + writer.writeAttribute("type", "hidden", null); + writer.writeAttribute("name", "ice.window", null); + writer.writeAttribute("value", WindowScopeManager.lookupWindowScope(context).getId(), null); + writer.endElement("input"); - writer.startElement("input", this); - writer.writeAttribute("type", "hidden", null); - writer.writeAttribute("name", "ice.window", null); - writer.writeAttribute("value", WindowScopeManager.lookupWindowScope(context).getId(), null); - writer.endElement("input"); + writer.startElement("input", this); + writer.writeAttribute("type", "hidden", null); + writer.writeAttribute("name", "ice.view", null); + writer.writeAttribute("value", viewId, null); + writer.endElement("input"); + } + }; - writer.startElement("input", this); - writer.writeAttribute("type", "hidden", null); - writer.writeAttribute("name", "ice.view", null); - writer.writeAttribute("value", viewId, null); - writer.endElement("input"); - } - }; + output.setTransient(true); + output.setId(componentId); + form.getAttributes().put(ADDED_WINDOWANDVIEWID, true); + form.getChildren().add(0, output); + } - output.setTransient(true); - output.setId(componentId); - form.getChildren().add(0, output); - } - - public boolean isListenerForSource(Object source) { - return source instanceof HtmlForm; - } + public boolean isListenerForSource(Object source) { + return source instanceof HtmlForm; + } }