Primefaces p:fileUpload doesnt work in IE 10

2019-02-18 00:28发布

Update attribute and onComplete in p:fileUpload doesnt work in IE10. In IE 9 sizeLimit attribute is ignored. Has anyone came across this situation.

I have tried calling p:remotecommand by using onComplete attribute on p:fileUoload but it looks like even onComplete doesn't work in IE 10

<h:form id="file" enctype="multipart/form-data">
        <p:outputLabel value="Test........"></p:outputLabel>
        <p:fileUpload label="Browse..." description="Select PDF file"
            auto="true" sizeLimit="500000"
            oncomplete="refreshData()"
            onstart="alert('test');" mode="advanced"
            fileUploadListener="#{fileUpload.handleFileUpload}"
            allowTypes="/(\.|\/)(pdf|png)$/">

        </p:fileUpload>
        <p:inputText value="#{fileUpload.test}" id="test" />
        <p:remoteCommand name="refreshData" action="#{fileUpload.setData}"
            update="test"></p:remoteCommand>
    </h:form>

6条回答
Ridiculous、
2楼-- · 2019-02-18 00:36

It seems to be a problem with position absolute. Change it to fixed. It works on my side:

.fileupload-buttonbar .ui-button input {
    ...
    position                          : fixed;
    ...
}
查看更多
趁早两清
3楼-- · 2019-02-18 00:43

I've got also problems with p:fileUpload after upgrading to IE10. The JavaScript errors began to occur ('syntax error in XML document').

It helped to change the X-UA-Compatible header to IE=EmulateIE9:

<h:head>
    <f:facet name="first">
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9,chrome=1" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    </f:facet>
<h:head>
查看更多
一夜七次
4楼-- · 2019-02-18 00:51

This is fixed in the new 4.0 Primefaces release, however if you are still on an older version of Primefaces you might still need a workaround.

I was able to update after a file upload by using the onstart attribute which does still work in IE 10.

Create a hidden field that contains a value that gets updated as part of the method called from the fileUploadListener. Then set the onstart attribute of the p:fileUpload to something like the following:

function checkUpload() {

    //this should call a p:remoteCommand that refreshes your hidden value
    refreshHiddenValue(); 

    var hiddenFieldValue = $('#hiddenFieldId').val();
    if(hiddenFieldValue) {
        //this should call a p:remoteCommand that refreshes the
        //sections you want refreshed after the upload has finished
        refreshSections();
    }
    else {
        setTimeout(checkUpload, 1000);
    } 
} 
查看更多
冷血范
5楼-- · 2019-02-18 00:52

I had to face this problem with PF 5.1 migrated from PF 3 and thanks to this post i resolved:

this is the html code generated:

<div class="ui-fileupload-buttonbar ui-widget-header ui-corner-top">
    <span class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-left ui-fileupload-choose" >
        <span class="ui-button-icon-left ui-icon ui-c ui-icon-plusthick"></span>
        <span class="ui-button-text ui-c">upload</span>
        <input name="upload" type="file">
    </span>
</div>

and this the CSS which resolved this problem:

.ui-fileupload-buttonbar .ui-fileupload-choose input
{
    position:absolute;
    top:0;
    right:0;
    margin:0;
    border:solid transparent;
    border-width:0 0 1px 1px;
    opacity:0;
    filter:alpha(opacity=0);
    -o-transform:translate(250px,  -50px) scale(1);
    direction:ltr;
    cursor:pointer;
    z-index:5000;
    width:100%;
    height: 20px;       
}

.ui-button {
    position: relative;
    overflow: hidden;
}
.ui-button input[type=file] {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 100%;
    min-height: 100%;
    font-size: 100px;
    text-align: right;
    filter: alpha(opacity=0);
    opacity: 0;
    outline: none;
    background: white;
    cursor: inherit;
    display: block;
}
查看更多
虎瘦雄心在
6楼-- · 2019-02-18 00:56

Use this CSS workaround. I derived this from the jQuery FileUpload component commit the fixed this issue.

.fileinput-button input {
    -moz-transform : none !important;
    border : none !important;
    border-width : 0 !important;
    transform : translate(-300px, 0) scale(4) !important;
    font-size : 23px !important;
}
* + html .fileinput-button {
    line-height : none !important;
    padding : 2px 15px !important;
}
查看更多
太酷不给撩
7楼-- · 2019-02-18 00:58

Finally realized that its a bug in primefaces.

http://forum.primefaces.org/viewtopic.php?f=3&t=28860#p94845

http://code.google.com/p/primefaces/issues/detail?id=5355

Fixed in:

TargetVersion-4.0
TargetVersion-3.5.9

查看更多
登录 后发表回答