【问题标题】:JSF 2.2 - ajax in form with multipart/form-data has some errorJSF 2.2 - 带有 multipart/form-data 的表单中的 ajax 有一些错误
【发布时间】:2013-03-21 17:21:40
【问题描述】:

我尝试使用 JSF 2.2 创建上传文件表单。 在这种形式中,我有 bankCode 输入框,当失去焦点时将 ajax 到服务器。 而且这个表格还包含输入文件框用。所以我必须将 enctype="multipart/form-data" 属性添加到 h:form 标记以上传文件。

每次我输入 enctype 时,ajax 都会在 Chrome 的调试器中显示错误消息。

未捕获的类型错误:无法读取 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 正式发布了吗?如果它没有,你应该期待错误

标签: java jsf jsf-2.2


【解决方案1】:

我向Mojarra 提出了一个错误,我认为这也与您的问题有关。

Stackoverflow issue

PS。投票支持 Jira 可能会加快解决速度,因为它自 5 月 14 日起处于休眠状态

【讨论】:

    【解决方案2】:

    感谢您的回复。 我发现这是 JSF 2.2 M10 到 M12 的错误。 我换成 JSF 2.2 M9,效果很好。

    所以我会使用 M9 直到 JSF 2.2 发布。

    【讨论】:

    • 你举报了吗?如果没有,它将不会出现在最终版本中。如果是这样,请发布报告链接。
    • 我仍然在 gassfish4 附带的 JSF 2.2 版本上发现了这个错误。我尝试谷歌几个星期,但还没有找到解决方案。请建议我解决它的方法。
    猜你喜欢
    • 2014-07-05
    • 2020-06-07
    • 2016-04-22
    • 2012-08-27
    • 2019-02-26
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 2019-06-10
    相关资源
    最近更新 更多