JSF 2.2 h:inputFile没有漂亮的面孔 [英] JSF 2.2 h:inputFile not working with pretty faces

查看:152
本文介绍了JSF 2.2 h:inputFile没有漂亮的面孔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用带有JSF 2.2(Mojarra 2.2.0)和PrettyFaces 2.0的Glassfish 4.0。
当使用 h:inputFile 以相应的格式 enctype =multipart / form-data $ c>,表单动作只会在页面被调用时触发,但如果调用漂亮的url,则不会发生任何事情。许多其他问题有一些类似的问题(例如如何使用PrimeFaces p:fileUpload?Listener方法永远不会被调用或者UploadedFile为空),但是他们中的大多数似乎使用PrimeFaces,并且在过滤器顺序等方面有困难。因为我们想要保持上传文件的JSF方法,我想知道是否有一些莫哈拉过滤器的配置,我可能已经错过了。


$ b web.xml 当前不包含任何过滤规范。



jsf文件只包含这个表格

$ p $ < h:form enctype =multipart / form-data >
< h:inputFile value =#{fileModel.testFile}/>
< h:commandButton value =Uploadaction =#{fileModel.upload}/>
< / h:表格>

和backing bean看起来像这样

  @ApplicationScoped 
@Named
public class FileModel {
$ b $ private part testFile;

public Part getTestFile(){
return testFile;
}

public void setTestFile(Part testFile){
this.testFile = testFile;
}

public void upload(){
System.out.println(File Data:+ testFile);






$ p然后,在<$ c $中取消注释这些行

 将会产生错误,而评论它们不会。 < url-mapping id =fileTest> 
< pattern value =/ file/>
< view-id value =/ view / fileTest.xhtml/>
< / url-mapping>

我想这个问题可能会被描述 by OCPSoft,但似乎还没有解决方案。

我的建议是:通过漂亮的脸书可收藏的页面,不应该包含任何提交表单!这种类型的页面应该只是为了查看,移动你的文件上传形式到另一个正常的jsf页面没有漂亮的过滤器


we're using a Glassfish 4.0 with JSF 2.2 (Mojarra 2.2.0) and PrettyFaces 2.0. When trying to upload a file using h:inputFile with the corresponding form enctype="multipart/form-data", the form action is only fired if the page is called directy, but nothing happens if the pretty url is called. Many other questions have some similar issues (e.g. How to use PrimeFaces p:fileUpload? Listener method is never invoked or UploadedFile is null), but most of them seem to use PrimeFaces and have difficulties with the order of the filters etc. Since we want to keep the JSF method for uploading files, I'd like to know if there is a configuration of some filters of Mojarra that I might have missed.

The web.xml does currently not contain any filter specs.

the jsf file contains only this form

<h:form enctype="multipart/form-data">
   <h:inputFile value="#{fileModel.testFile}"/>
   <h:commandButton value="Upload" action="#{fileModel.upload}"/>
</h:form>

and the backing bean looks like this

@ApplicationScoped
@Named
public class FileModel {

    private Part testFile;

    public Part getTestFile() {
        return testFile;
    }

    public void setTestFile(Part testFile) {
        this.testFile = testFile;
    }

    public void upload() {
        System.out.println("File Data: " + testFile);
    }
}

then, uncommenting these lines in the pretty-config.xml will yield the error, while commenting them won't.

<url-mapping id="fileTest">
    <pattern value="/file" />
    <view-id value="/view/fileTest.xhtml" />
</url-mapping>

I think the problem might be described in this post by OCPSoft, but there doesn't seem to be a solution yet.

解决方案

My suggestion is: page which is bookmarkable via pretty faces, should not contain any submit form! That kind of page should be only for view, move your file upload form to another regular jsf page without prettyfaces filter

这篇关于JSF 2.2 h:inputFile没有漂亮的面孔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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