2012-01-07 12 views
0

RichFacesを使用してファイルをアップロードしようとしていますが、ファイルをアップロードしていません。私が行っている何 は次のとおりです。
file.jsp転送エラーが発生しました

<h:form> 
     <rich:panel header="FileUpload demostration"> 
      <rich:fileUpload 
       fileUploadListener="#{fileUploadBean.listener}" 
       id="upload" 
       maxFilesQuantity="10" 
       immediateUpload="true" 
      /> 
     </rich:panel> 
</h:form> 

file.java

public class FileUploadBean { 

private List<String> uploadedList; 
private UploadItem item; 

public FileUploadBean(){ 
    this.uploadedList = new LinkedList<String>(); 
} 

public void listener(UploadEvent event) throws IOException { 
    this.setItem(event.getUploadItem()); 
    getUploadedList().add(this.getItem().getFileName()); 
    System.out.println("Elements in the list: "); 
    for(String name : this.getUploadedList()){ 
     System.out.println(name); 
    } 
} 

/** 
* @return the uploadedList 
*/ 
public List<String> getUploadedList() { 
    return uploadedList; 
} 

/** 
* @param uploadedList the uploadedList to set 
*/ 
public void setUploadedList(List<String> uploadedList) { 
    this.uploadedList = uploadedList; 
} 

/** 
* @return the item 
*/ 
public UploadItem getItem() { 
    return item; 
} 

/** 
* @param item the item to set 
*/ 
public void setItem(UploadItem item) { 
    this.item = item; 
} 

} と私はweb.xmlにこの追加:私が実行したときに

<context-param> 
    <param-name>org.richfaces.SKIN</param-name> 
    <param-value>blueSky</param-value> 
</context-param> 
<context-param> 
    <param-name>org.richfaces.CONTROL_SKINNING</param-name> 
    <param-value>enable</param-value> 
</context-param> 
<filter> 
    <display-name>RichFaces Filter</display-name> 
    <filter-name>richfaces</filter-name> 
    <filter-class>org.ajax4jsf.Filter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>richfaces</filter-name> 
    <servlet-name>Faces Servlet</servlet-name> 
    <dispatcher>REQUEST</dispatcher> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>INCLUDE</dispatcher> 
</filter-mapping> 

をそれは私のJSPページを与える、私は画像を選択することができますが、私はuloadを行うときそれはtransfer error occuredとこの行で起こると言う: '#{fileUploadBean.listener}' java.lang.NullPointerException

どこが間違っていますか? ありがとうございました!

答えて

0

あなたは<filter-mapping>タグの前のweb.xmlでこれを追加する必要があります:

<filter> 
<display-name>Ajax4jsf Filter</display-name> 
<filter-name>ajax4jsf</filter-name> 
<filter-class>org.ajax4jsf.Filter</filter-class> 
<init-param> 
    <param-name>createTempFiles</param-name> 
    <param-value>false</param-value> 
</init-param> 
</filter> 
関連する問題