Change the upload directory path for an ice:inputF

2019-08-16 13:51发布

问题:

I've noticed that the ice:inputFile component will only upload files to the directory $TOMCAT_HOME/webapps/MyAppName/upload/. I want this directory to be dependent on the user initials for the current user (i.e. user with initials abc wants to upload a file, the file goes to $TOMCAT_HOME/webapps/MyAppName/upload/abc/). How can I dynamically set this attribute?

回答1:

As indicated in the reference guide http://www.icefaces.org/docs/v1_8_2/htmlguide/devguide/references5.html

web.xml file:

To specify the directory location where uploaded files are stored, the following parameter is used:

<param-name>com.icesoft.faces.uploadDirectory</param-name>

<param-value>youruploaddirectory</param-value>

This parameter works in conjunction with the ice:inputFile component attribute "uniqueFolder" with four possible combinations as illustrated below:

                           **com.icesoft.faces.uploadDirectory**

                                   Set                                 Not Set

  **uniqueFolder**

   True           /app-context/uploadDirectory/sessionid/     /app-context/sessionid/

   False          /app-context/uploadDirectory/           /app-context/         

Note: The default upload directory specified via the configuration parameters above can be overridden on a per-instance basis via the uploadDirectory and uploadDirectoryAbsolute attributes on the ice:inputFile component.

Hope this helps!



回答2:

Need to set the property uploadDirectory on the component, as such:

<ice:inputFile file="#{Bean.file}" uploadDirectory="./upload/#{Bean.userInitials}/"/>

This property is (currently) not mentioned in the JavaDoc for this component on the ICEFaces site.