JSF2上传照片与primefaces问题

问题描述:

我使用下面的片段上传照片,使用primefaces:JSF2上传照片与primefaces问题

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" 
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" 
xmlns:p="http://primefaces.org/ui"> 
    <h:outputText value="PrimeFaces Single Upload" /> 
    <h:form enctype="multipart/form-data"> 
     <p:fileUpload fileUploadListener="#{uploadPhotoHandler.handleFileUpload}" mode="advanced" 
      update="messages" label="Choose a file" sizeLimit="5242880" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" 
      invalidSizeMessage="The maximum file size allowed is 1 Megabyte !" 
      invalidFileMessage="You are allowed to upload only images !" /> 
     <p:growl id="messages" showDetail="true" sticky="true" /> 

该组合物我使用下面的命令添加到主页,这是index.xhtml<ui:include src="upload_img_form.xhtml" />

主要页面的样子:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:p="http://primefaces.org/ui"> 
<h:head> 
    <script type="text/javascript" src="js/jquery-1.9.1.js"></script> 
    <script type="text/javascript" src="js/jquery-migrate-1.1.1.js"></script> 
    <script type="text/javascript" src="js/jquery.ui.widget.js"></script> 
    <script type="text/javascript" src="js/jquery.xdr-transport.js"></script> 
    <script type="text/javascript" src="js/jquery.fileupload.js"></script> 
    <script type="text/javascript" src="themes/jquery-ui-1.10.0.custom/js/jquery-ui-1.10.0.custom.min.js"></script> 
    <link type="text/css" rel="stylesheet" href="themes/jquery-ui-1.10.0.custom/css/sunny/jquery-ui-1.10.0.custom.css" /> 
    <link type="text/css" rel="stylesheet" href="css/base.css" /> 
    <link type=" text/css" rel="stylesheet" href="css/styles.css" /> 
</h:head> 
<h:body> 
    <div id="container" class="container "> 
     <ui:include src="upload_img_form.xhtml" /> 
    </div> 
</h:body> 
</html> 

我有以下问题:

  • 进度条不工作,
  • 取消按钮不起作用,而最大问题是sizeLimit不会验证作为输入提供的文件。
  • 即使这不是autoupload,文件是autouploaded,没有点击上传按钮之前。

该问题与head部分100%相关,因为如果我删除它,它就会起作用。虽然,它不适用于同一页面的其他功能,所以我必须保留js文件和styles

感谢您的回复。

+0

SSCCE会有帮助。你的构图确实很奇怪。通常,“h:head”和“h:body”进入主模板,并且不会在子模板中重复。你有[验证](http://validator.w3.org)HTML吗?另见http://stackoverflow.com/questions/4792862/how-to-include-another-xhtml-in-xhtml-using-jsf-2-0-facelets/4793959#4793959 – BalusC 2013-02-19 12:11:52

+0

@BalusC我已更新并尝试在问题上更清楚。该问题与主页面的头部相关100%。 (我不知道为什么我不能在问题中格式化main.xhtml代码)。你能提供吗?非常感谢。我感谢您的帮助! – Ioan 2013-02-19 12:37:49

+0

为什么你手动包括jQuery和所有的时间? PrimeFaces已经自动包含jQuery,它只会与您手动包含的jQuery相冲突。至于代码格式,只需选择代码并按消息编辑器工具栏中的“{}”按钮即可。 – BalusC 2013-02-19 12:39:37

摆脱手动包含的jQuery。 PrimeFaces已经自动包含自己的副本。如果它们是不同的版本,它只会发生冲突,导致所有颜色的JS相关的麻烦。如果您在浏览器的开发人员工具集中检查了JS控制台,您会注意到它。

+0

非常感谢您的帮助。我也非常感谢你对JSF和web相关内容的所有贡献。 – Ioan 2013-02-19 12:43:04

+0

不客气。 – BalusC 2013-02-19 12:43:16

+0

但有一个问题:我直到现在使用jquery的menu()功能。现在所有jquery js都已经离开了,我有一个错误,说Object对象没有方法菜单。我应该忘记jQuery的东西,只专注于primefaces?或者,这是一种方法,但是,使用jQuery的功能(如果有一个副本内的jquery primefaces)。谢谢 – Ioan 2013-02-19 12:50:03