Ajax更改multipart/form-data表单上的target属性 [英] ajax changes target attribute on multipart/form-data form

查看:87
本文介绍了Ajax更改multipart/form-data表单上的target属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在 multipart/form-data 表单中渲染带有f:ajax的组件时,该表单的 target 属性被更改为 JSFFrameId .这是一个错误吗?

When I try to render a component with f:ajax inside a multipart/form-data form, the target attribute of the form gets changed to JSFFrameId. Is this a bug?

以下是发生这种情况的示例代码:

Here is a sample code when this occur:

<h:form enctype="multipart/form-data">
    <h:inputText>
        <f:ajax event="change" render="@this" execute="@this"/>
    </h:inputText>
    <h:inputFile />
</h:form>

在我的真实代码中,这不是我要尝试执行的操作,但是示例代码中出现了相同的问题.

In my real code this is not what I'm trying to do but the same issue occurs with the sample code.

访问此页面时,我得到以下HTML输出:

When visiting this page I get the following HTML output:

<form id="form" name="form" method="post" action="/AdApp/faces/test.xhtml" enctype="multipart/form-data">
    <input type="hidden" name="form" value="form">
    <input id="form-textfield" type="text" name="form-textfield" onchange="mojarra.ab(this,event,'change','@this','@this')">
    <input id="form-filefield" type="file" name="form-filefield">
    <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-0" value="-1920816151200438245:-3719618601043085373" autocomplete="off">
</form>

这里没问题.但是当ajax事件触发时,这就是HTML输出(我的问题?表单的target属性)发生的情况:

Nothing wrong here. But when the ajax event triggers, this is what happends with the HTML output(My issue? target attribute of the form):

<form id="form" name="form" target="JSFFrameId" method="POST" action="http://DOMAIN_PATH/AdApp/faces/test.xhtml" enctype="multipart/form-data">
    <input type="hidden" name="form" value="form">
    <input id="form-textfield" type="text" name="form-textfield" onchange="mojarra.ab(this,event,'change','@this','@this')">
    <input id="form-filefield" type="file" name="form-filefield">
    <input type="hidden" name="javax.faces.ViewState" id="j_id1-javax.faces.ViewState-0" value="-1920816151200438245:-3719618601043085373" autocomplete="off">
</form>
<iframe src="about:blank" id="JSFFrameId" name="JSFFrameId" width="0" height="0" frameborder="0">
    <partial-response id="j_id1">
        <changes>
            <update id="form-textfield">
                <![CDATA[<input id="form-textfield" type="text" name="form-textfield" value="das" onchange="mojarra.ab(this,event,'change','@this','@this')" />]]>
            </update>
            <update id="j_id1-javax.faces.ViewState-0">
                <![CDATA[-1920816151200438245:-3719618601043085373]]>
            </update>
        </changes>
    </partial-response>
</iframe>

我不在乎iframe保留更改记录.我的问题是表格的目标已更改.因此,在ajax事件触发后,提交将针对隐藏的iframe,而不是窗口本身.

I don't care about the iframe keeping a record of the changes. My issue is that the target of the form has been changed. So after the ajax event triggers, a submit will target a hidden iframe and not the window itself.

如果我删除 enctype 属性或将ajax设置为呈现 @form ,它不会更改 target 属性.我需要 enctype ="multipart/form-data" 来上传文件,并且我不想使用 render ="@ form" ,因为某些内容是真实的表单可能已被javascript代码修改.我想念什么吗?还是虫子?我将添加一些JavaScript来删除target属性,但是如果我做错了什么,我应该使用另一种方法.

If I remove the enctype attribute or set ajax to render @form instead, it doesn't change the target attribute. I need the enctype="multipart/form-data" to upload files, and I dont want to use render="@form" because some of the content in my real form might have been modified by javascript code. Am I missing something? Or just bug? I will add some javascript to remove the target attribute but if I'm doing something wrong, I should use another approach.

我正在使用以下工具:

Netbeans IDE 8

Netbeans IDE 8

带有Mojarra 2.2.7的玻璃鱼4

Glassfish 4 with Mojarra 2.2.7

推荐答案

似乎有一对夫妇( 2843 3018

There appear to be a couple (2843, 3018, 3048) of bugs related to fileuploads and ajax-reloads. They all are marked as resolved in various versions (JSF 2.2.1 and 2.2.5). I am on 2.2.3 and I am not in charge of the JSF versioning so i'm stuck with that. I tried 2.2.8 on my development machine, but could still reproduce the problem.

与您一样,我还发现使用render="@form"会导致更改消失的问题.但是,如果我还添加execute="@form",则更改将存储在Bean中,并且在渲染后仍然可见.

Like you, i also found out that using render="@form" leads to a problem with disappearing changes. However, if I also add execute="@form" the changes are stored in the bean and are remain visible after the render.

这篇关于Ajax更改multipart/form-data表单上的target属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆