2013-08-14 2 views
0

내 서버에 텍스트 문서를 업로드하려고하는데 며칠 동안 미친 듯이 움직입니다. 기본적으로 파일이 업로드 될 때 # {bookController.handleFileUpload}이 (가) 발생하는 메소드는 실행되지 않지만 오류는 발생하지 않으며 프런트 엔드에서는 파일이 업로드 된 것처럼 보입니다. 파일이 내 컨트롤러 메소드로가는 도중에 소비된다고 가정합니다. 여기 내 pom.xml 파일에 필요한 항아리 (공통 io.jar & 공통 fileupload.jar)을 추가 내 web.xml을파일 업로드 java/jsf/primefaces

<filter> 
    <filter-name>PrimeFaces FileUpload Filter</filter-name> 
    <filter-class> 
     org.primefaces.webapp.filter.FileUploadFilter 
    </filter-class> 
</filter> 
    <filter-mapping> 
    <filter-name>PrimeFaces FileUpload Filter</filter-name> 
    <servlet-name>Faces Servlet</servlet-name> 
    </filter-mapping> 
    <context-param> 
    <param-name>primefaces.THEME</param-name> 
    <param-value>south-street</param-value> 
    </context-param> 
    <servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>*.faces</url-pattern> 
    </servlet-mapping> 
    <servlet> 
    <servlet-name>appServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>/jpmorgan/*</url-pattern> 
    </servlet-mapping> 
    <context-param> 

입니다.

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:p="http://primefaces.org/ui" 
    template="/WEB-INF/layouts/no-ajax.xhtml"> 

    <ui:define name="head"> 

    </ui:define> 

    <ui:define name="title">#{msg['add_book']}</ui:define> 

    <ui:define name="content"> 
     <h:form id="form" enctype="multipart/form-data"> 

      <p:messages id="messages" autoUpdate="true"/> 
      <p:panelGrid id="grid"> 

      <p:row> <p:column> 
       <h:outputLabel for="name" value="#{msg['label_book_title']}" /> 
       <p:spacer width="100" height="10" /> 
       <p:inputText id="name" value="#{bookBean.book.title}"/> 
      </p:column> </p:row>  
      <p:row> <p:column> 

       <p:fileUpload id="upload" value="#{bookBean.file}" 
           dragDropSupport="true" 
           update="messages" 
           fileUploadListener="#{bookController.handleFileUpload}" /> 

      </p:column> </p:row> 
      </p:panelGrid> 

      <p:toolbar> 
       <p:toolbarGroup align="left"> 
        <p:commandButton value="#{msg['button_next']}" action="next" execute="@form" update="@form"/> 
        <p:commandButton value="#{msg['button_cancel']}" action="exit" execute="@form" update="@form"/> 
       </p:toolbarGroup> 
      </p:toolbar> 

     </h:form> 
    </ui:define> 

    <ui:define name="help"> 

    <h:outputText value="#{msg['help_add_page']}" /> 

    </ui:define> 

</ui:composition> 

그리고 위의 페이지 레이아웃 : 다음 파일을 처리하기 위해 가정 내 페이지입니다

<?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 xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:sec="http://www.springframework.org/security/tags" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 

<f:view contentType="text/html"> 

    <h:head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <title>#{msg['application_name']}</title> 

     <link rel="icon" href="resources/resources/images/favicon.ico" type="image/x-icon" /> 
     <link rel="shortcut icon" href="resources/resources/images/favicon.ico" /> 
     <link rel="stylesheet" href="resources/resources/styles/blueprint/screen.css" type="text/css" media="screen, projection" /> 
     <link rel="stylesheet" href="resources/resources/styles/blueprint/print.css" type="text/css" media="print" /> 
     <!--[if lt IE 8]> 
      <link rel="stylesheet" href="${request.servletPath}/styles/blueprint/ie.css" type="text/css" media="screen, projection" /> 
     <![endif]--> 
    </h:head> 

    <h:body> 
     <p:layout fullPage="true"> 

      <p:layoutUnit id="top" position="north" header="#{msg['application_name']}" size="100" collapsible="true" collapsed="false" resizable="true"> 
       <ui:insert name="title" /> 
      </p:layoutUnit> 

      <p:layoutUnit id="west" position="west" size="250" header="#{msg['label_help']}" resizable="true" collapsible="true" collapsed="false"> 
       <ui:insert name="help" /> 
      </p:layoutUnit> 

      <p:layoutUnit id="center" position="center" > 
       <ui:insert name="content" /> 
      </p:layoutUnit> 

     </p:layout> 

    </h:body> 

</f:view> 
</html> 

사람이 내가 잘못 무슨 생각을 가지고 있습니까? 큰 감사.

+0

안녕하세요 BalusC, 나는 다른 프로젝트에서 코드를 실행할 수 있었지만 한 번 이동하면 내 코드가 작동하지 않습니다. 몇 가지 예가 있지만 web.xml에서 더 많은 설정을 사용한다는 차이점이 있습니다. 레이아웃 요소 만 포함 된 layout.xhtml 및 양식이 없어도 프로젝트에서 더 간단하게 만들려고했지만 여전히 작동하지 않습니다. – Lukasz

+0

문제는 코딩 부분에 있지 않지만 구성 부분 (web.xml)에는 있습니다. – Lukasz

답변

0

문제는 <p:commandButton value="#{msg['button_next']}" action="next" execute="@form" update="@form"/>에 있다고 생각합니다. AJAX를 사용하여 파일을 업로드 할 수 없으므로 p:commandButtonajax="false"을 추가해야합니다. 액션 대신 actionListener를 사용해야하지만 lattern에서는 확실하지 않습니다. 귀하의 상황에서 https://www.primefaces.org/showcase/ui/file/upload/single.xhtml의 샘플을 시도해보십시오.

1

코드는 당신이 JSF 2.2 Primefaces 5.3

와 함께 일해야 같은 문제가 있었다 올바른 것 같다

업로드 내 코드

public void uploadPhoto(FileUploadEvent e) throws IOException { 

    UploadedFile uploadedPhoto = e.getFile(); 

    String filePath = "TO/THE/PATH"; 
    byte[] bytes = null; 

    if (null != uploadedPhoto) { 
     bytes = uploadedPhoto.getContents(); 
     String filename = FilenameUtils 
       .getName(uploadedPhoto.getFileName()); 
     BufferedOutputStream stream = new BufferedOutputStream(
       new FileOutputStream(new File(filePath + filename))); 
     stream.write(bytes); 
     stream.close(); 
    } 
    setProduitIMG(uploadedPhoto.getFileName()); 
    setImageSize(uploadedPhoto.getSize()); 

    FacesContext.getCurrentInstance().addMessage(
      "messages", 
      new FacesMessage(FacesMessage.SEVERITY_INFO, 
        "Your Photo (File Name " + uploadedPhoto.getFileName() 
          + " with size " + uploadedPhoto.getSize() 
          + ") Uploaded Successfully", "")); 
} 

은 당신이 당신의 관리 빈에서 사용할 수있다 그것은 당신이 어떤 managedbean과 병합 할 수있는 새로운 fileBean을 만들 필요가 없습니다. 클래스 잘 작동합니다.

JSF 2.1 OR 2.0은 스프링 통합과 함께 작동하지 않습니다. 프로젝트를 업그레이드해야합니다.