2013-02-19 54 views
0

我使用下面的片段上傳照片,使用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

回答

1

擺脫手動包含的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