2017-10-08 3 views
0

私は、正しい依存関係(私は思う)と私がprimefacesショーケースで見つけたのと同じコードを使って、単純なJSF/CDIプロジェクトでFileUpload機能を実装しようとしています。方法が見つかりませんか?これは意味がありません

しかし、何らかの理由で、FileUploadイベントでManagedBeanのリスナーが見つかりませんでした。

私はここで紛失しているものを見ることができます、私はすでに多くの時間コードを検査しましたが、私は問題を引き起こす可能性のあるものは見つけられません。

マイXHTMLページ:

<html> 
<h:head> 
</h:head> 

<body> 
    <h:form> 
     <p:fileUpload fileUploadListener="#{file.uploadHandler()}" 
      mode="advanced" dragDropSupport="false" update="messages" 
      sizeLimit="100000" fileLimit="3" 
      allowTypes="/(\.|\/)(gif|jpe?g|txt)$/" /> 
     <p:growl id="messages" showDetail="true" /> 
    </h:form> 
</body> 
</html> 

マイManagedBean:

import javax.faces.view.ViewScoped; 
import javax.inject.Named; 

import org.primefaces.event.FileUploadEvent; 

@Named 
@ViewScoped 
public class File implements Serializable { 

    private static final long serialVersionUID = -6644472075906217176L; 
    private String fileName; 

    public String getFileName() { 
     return fileName; 
    } 

    public void setFileName(String fileName) { 
     this.fileName = fileName; 
    } 

    public void uploadHandler(FileUploadEvent event) { 
     System.out.println("Nome do Arquivo: " + event.getFile().getFileName()); 
    } 
} 

マイpom.file:

<properties> 
    <maven.compiler.source>1.8</maven.compiler.source> 
    <maven.compiler.target>1.8</maven.compiler.target> 
</properties> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>3.7.0</version> 
      <configuration> 
       <source>1.8</source> 
       <target>1.8</target> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

<dependencies> 
    <dependency> 
     <groupId>javax.faces</groupId> 
     <artifactId>jsf-api</artifactId> 
     <version>2.1</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.faces</groupId> 
     <artifactId>jsf-impl</artifactId> 
     <version>2.2.14</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>javax.servlet-api</artifactId> 
     <version>3.0.1</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.primefaces</groupId> 
     <artifactId>primefaces</artifactId> 
     <version>6.1</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.enterprise</groupId> 
     <artifactId>cdi-api</artifactId> 
     <version>2.0</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>javax</groupId> 
     <artifactId>javaee-api</artifactId> 
     <version>7.0</version> 
     <scope>provided</scope> 
    </dependency> 
</dependencies> 

コンソール:

15:59:36,935 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-27) /index.xhtml @16,45 fileUploadListener="#{file.uploadHandler()}": Method not found: class timesheet.business.bean.File.uploadHandler(): javax.el.MethodNotFoundException: /index.xhtml @16,45 fileUploadListener="#{file.uploadHandler()}": Method not found: class timesheet.business.bean.File.uploadHandler() 
+0

あなたのメソッドはパラメータを受け取りますが、ELにパラメータを渡すことはありません。 – chrylis

答えて

0

あなたは、メソッド名の後に何()があってはならないことに注意してくださいfileUploadコンポーネント

<p:fileUpload fileUploadListener="#{file.uploadHandler}" 

におけるメソッド参照を指定する必要があります。

関連する問題