Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot use javascript to submit() seam form
    primarykey
    data
    text
    <p>Hi I have a seam form that we use to upload an attachment to our java code. Everything was working fine until we needed to display a jquery dialog to give the user some visual feedback that the upload was taking place.</p> <p>To do this we intercept the onsubmit event via javascript, put up the jquery dialog then a second later submit the form via <code>document.forms[...].submit()</code>.</p> <p>Everything looks like it is working, the message appears, a second later we see the browser is transferring data to the server, but seam does not invoke the action of the form. The page simply refreshes and nothing happens.</p> <p>If I remove the javascript submit() and let the form get submitted in the normal submit button click seam processes the action on the server normally.</p> <p>My seam form:</p> <pre><code>&lt;h:form onsubmit="return ClickSuperUtil.submitForm();" enctype="multipart/form-data"&gt; &lt;s:validateAll&gt; &lt;h:panelGrid columns="2"&gt; &lt;h:outputText rendered="false" value="#{messages['document_type']}:" /&gt; &lt;h:selectOneMenu rendered="false" value="#{document.documentType}" required="true"&gt; &lt;f:selectItem itemLabel="#{messages['dt_rollover']}" itemValue="ROLLOVER" /&gt; &lt;f:selectItem itemLabel="#{messages['dt_sg_contribution']}" itemValue="SG_CONTRIBUTION" /&gt; &lt;/h:selectOneMenu&gt; &lt;h:outputText value="#{messages['document_format']}:" /&gt; &lt;h:selectOneMenu value="#{document.documentFormat}" required="true"&gt; &lt;s:selectItems value="#{uploadHistoryManager.contributionFormatList}" var="contributionFormat" label="#{contributionFormat}" noSelectionLabel="Please Select..."/&gt; &lt;/h:selectOneMenu&gt; &lt;h:outputText value="#{messages['upload_document']}:" /&gt; &lt;s:fileUpload data="#{document.uploadedDocument}" fileName="#{document.documentName}" fileSize="#{document.documentSize}" /&gt; &lt;/h:panelGrid&gt; &lt;/s:validateAll&gt; &lt;h:commandButton styleClass="menubutton" value="#{messages['upload']}" action="#{uploader.upload}"&gt; &lt;f:param name="fileUploaded" value="fileUploaded" /&gt; &lt;s:conversationId/&gt; &lt;/h:commandButton&gt; &lt;/h:form&gt; </code></pre> <p>My javascript function that handles the form onsubmit event:</p> <pre><code>ClickSuperUtil.submitForm=function() { if(this.messageDisplayed == null) { this.showPleaseWaitDialog(); this.messageDisplayed = true setTimeout("document.getElementById('uploadPanel').getElementsByTagName('form')[0].submit()",1000) return false } this.messageDisplayed = null return true } </code></pre> <p>Further research shows that the "normal" post includes the conversationId appended to the referer in the headers but the javascript initiated post does not.</p> <p><strong>Normal post headers:</strong></p> <pre><code>POST /connectweb/upload.seam HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 GTB7.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Referer: http://localhost:8080/connectweb/upload.seam?conversationId=73 Cookie: JSESSIONID=309AA62DD4929392DD9561389F5A36BA ... </code></pre> <p><strong>Javascript initiated post headers</strong></p> <pre><code>POST /connectweb/upload.seam HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 GTB7.1 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 115 Connection: keep-alive Referer: http://localhost:8080/connectweb/upload.seam Cookie: JSESSIONID=309AA62DD4929392DD9561389F5A36BA ... </code></pre> <p>The html for the form as generated by seam:</p> <pre><code>&lt;form onsubmit="return ClickSuperUtil.submitForm();" enctype="multipart/form-data" action="/connectweb/upload.seam" method="post" name="j_id14" id="j_id14"&gt; &lt;input type="hidden" value="j_id14" name="j_id14"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;Document Format:&lt;/td&gt; &lt;td&gt;&lt;select size="1" name="j_id14:j_id22"&gt; &lt;option value="org.jboss.seam.ui.NoSelectionConverter.noSelectionValue"&gt;Please Select...&lt;/option&gt; &lt;option value="CUSCAL"&gt;CUSCAL&lt;/option&gt; &lt;option value="ORACLE"&gt;ORACLE&lt;/option&gt; &lt;option selected="selected" value="ROCKFAST"&gt;ROCKFAST&lt;/option&gt; &lt;/select&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Upload Document:&lt;/td&gt; &lt;td&gt;&lt;input type="file" name="j_id14:j_id25" id="j_id14:j_id25"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;input type="submit" class="menubutton" value="Upload" name="j_id14:j_id26"&gt;&lt;input type="hidden" autocomplete="off" value="H4sIAAAAAA ... /B7CYBAA==" id="javax.faces.ViewState" name="javax.faces.ViewState"&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload