1 16 package org.apache.myfaces.renderkit.html.util; 17 18 import org.apache.myfaces.config.MyfacesConfig; 19 import org.apache.myfaces.renderkit.html.HTML; 20 import org.apache.myfaces.renderkit.html.HtmlRendererUtils; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import javax.faces.application.StateManager; 26 import javax.faces.application.ViewHandler; 27 import javax.faces.context.FacesContext; 28 import javax.faces.context.ResponseWriter; 29 import java.io.IOException ; 30 import java.util.Map ; 31 import java.util.Set ; 32 33 50 public class DummyFormUtils 51 { 52 private static final Log log = LogFactory.getLog(DummyFormUtils.class); 53 54 private static final String DUMMY_FORM_RESPONSE_WRITER_WRAPPER_REQ_PARAM 55 = DummyFormUtils.class.getName() + ".INSTANCE"; 56 57 public static final String DUMMY_FORM_NAME = "linkDummyForm"; 58 private static final String DUMMY_FORM_ID = "linkDummyForm"; 59 60 66 public static DummyFormResponseWriter getDummyFormResponseWriter(FacesContext facesContext) 67 { 68 ResponseWriter currentWriter = facesContext.getResponseWriter(); 69 if (currentWriter instanceof DummyFormResponseWriter) 70 { 71 return (DummyFormResponseWriter)currentWriter; 74 } 75 else 76 { 77 Map requestMap = facesContext.getExternalContext().getRequestMap(); 80 DummyFormResponseWriterWrapper writer 81 = (DummyFormResponseWriterWrapper)requestMap.get(DUMMY_FORM_RESPONSE_WRITER_WRAPPER_REQ_PARAM); 82 if (writer != null) 83 { 84 return writer; 86 } 87 else 88 { 89 writer = new DummyFormResponseWriterWrapper(currentWriter); 91 facesContext.setResponseWriter(writer); 92 requestMap.put(DUMMY_FORM_RESPONSE_WRITER_WRAPPER_REQ_PARAM, writer); 93 log.debug("DummyFormResponseWriterWrapper installed"); 94 return writer; 95 } 96 } 97 } 98 99 100 public static void writeDummyForm(ResponseWriter writer, 101 Set dummyFormParams) throws IOException 102 { 103 FacesContext facesContext = FacesContext.getCurrentInstance(); 104 ViewHandler viewHandler = facesContext.getApplication().getViewHandler(); 105 String viewId = facesContext.getViewRoot().getViewId(); 106 String actionURL = viewHandler.getActionURL(facesContext, viewId); 107 108 writer.startElement(HTML.FORM_ELEM, null); 110 writer.writeAttribute(HTML.ID_ATTR, DUMMY_FORM_ID, null); 111 writer.writeAttribute(HTML.NAME_ATTR, DUMMY_FORM_NAME, null); 112 writer.writeAttribute(HTML.STYLE_ATTR, "display:inline", null); 113 writer.writeAttribute(HTML.METHOD_ATTR, "post", null); 114 writer.writeURIAttribute(HTML.ACTION_ATTR, 115 facesContext.getExternalContext().encodeActionURL(actionURL), 116 null); 117 writer.flush(); 118 119 StateManager stateManager = facesContext.getApplication().getStateManager(); 120 if (stateManager.isSavingStateInClient(facesContext)) 121 { 122 StateManager.SerializedView serializedView = stateManager.saveSerializedView(facesContext); 125 stateManager.writeState(facesContext, serializedView); 126 } 127 128 if (MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isAutoScroll()) 129 { 130 JavascriptUtils.renderAutoScrollHiddenInput(writer); 131 } 132 133 if (dummyFormParams != null) 134 { 135 HtmlRendererUtils.renderHiddenCommandFormParams(writer, dummyFormParams); 136 HtmlRendererUtils.renderClearHiddenCommandFormParamsFunction(writer, 137 DUMMY_FORM_NAME, 138 dummyFormParams, null); 139 } 140 141 writer.endElement(HTML.FORM_ELEM); 142 } 143 144 145 } 146 | Popular Tags |