我嘗試使用JSF 2.2創建上載文件表單。 在這種形式中,我有bankCode輸入框,它會在丟失焦點時將ajax發送到服務器。 而且這個表格還包含輸入文件框。所以我必須把enctype =「multipart/form-data」屬性設置爲h:form標籤才能上傳文件。JSF 2.2 - 與多部分/表單數據形式的ajax有一些錯誤
每當我把enctype形成--ajax會在Chrome的debuger中顯示錯誤信息。
Uncaught TypeError: Cannot read property 'length' of null
jsf.js.htm:359
示例代碼
<h:form id="dialogForm" prependId="false" enctype="multipart/form-data">
<h:commandLink action="#{bankController.initCreate()}" class="btn add" style="margin: 10px 0 20px 20px;">
<f:ajax immediate="true" execute="@this" render=":dialogForm"/>
<span>Add new bank</span>
</h:commandLink>
<table class="dialogTable" style="margin: 10px 0 20px 20px;">
<colgroup>
<col width="30%"/>
<col width="70%"/>
</colgroup>
<tr>
<td class="label">
<label for="abbreviation">Bank's code<span class="required">*</span></label>
</td>
<td>
<h:panelGroup id="codeBox" layout="block" class="codeBox">
<h:inputText id="code" value="#{bankController.curBank.code}" maxlength="10" class="input code #{bankController.isExistCode?'error':''}"
onblur="return validTextInput('code',2);">
<f:validateLength minimum="2" maximum="10"/>
<f:ajax execute="@this" event="blur" listener="#{bankController.existCode()}" onevent="function(e){showValidateIcon(e, 'code');}" render="codeBox"/>
</h:inputText>
<span class="append2">
<img id="codeXLoad" src="#{cdnLocator.officeUrl}/img/load16.gif" title="On process, please wait" width="16" height="16" style="margin-top: 2px; display: none;"/>
<img id="codeXWarn" src="#{cdnLocator.officeUrl}/css/images/error_msg_icon.gif" title="Not allowed" width="16" height="16" style="margin-top: 2px; #{bankController.isExistCode?'':'display: none;'}"/>
<img id="codeXAvai" src="#{cdnLocator.officeUrl}/css/images/success_msg_icon.gif" title="Allowed" width="16" height="16" style="margin-top: 2px; #{bankController.isExistCode?'display: none;':''}"/>
</span>
</h:panelGroup>
</td>
</tr>
<tr>
<td class="label">
<label for="icon">Bank icon file*</label>
</td>
<td>
<h:inputFile id="bankIconFile" value="#{bankController.bankIconFile}"/>
</td>
</tr>
</table>
</h:form>
我怎樣才能解決這個錯誤。
您的問題可能與我看到的一些潛在問題有關。 'onblur'javascript可能不會在'blur'ajax事件之前執行,或者'validateTextInput' javascript函數可能存在代碼問題。看到Javascript的代碼將告訴我們更多。 –
JSF 2.2是否正式發佈?你應該期待錯誤,如果它沒有 – kolossus