Class WMultiFileWidget

    • Field Detail

      • FILE_UPLOAD_MULTI_PART_ID_KEY

        public static final String FILE_UPLOAD_MULTI_PART_ID_KEY
        File id for file content included in multi part request.
        See Also:
        Constant Field Values
      • FILE_UPLOAD_THUMB_NAIL_KEY

        public static final String FILE_UPLOAD_THUMB_NAIL_KEY
        File id thumb nail content request.
        See Also:
        Constant Field Values
    • Constructor Detail

      • WMultiFileWidget

        public WMultiFileWidget()
    • Method Detail

      • getValueAsString

        public String getValueAsString()
        Retrieves a String representation of the input field's value.
        Specified by:
        getValueAsString in interface Input
        Overrides:
        getValueAsString in class AbstractInput
        Returns:
        the String representation of the input field's value
      • getMimeType

        public String getMimeType​(String fileId)
        Retrieves an mime type of the uploaded file's contents. This is not the content type passed by the browser.
        Parameters:
        fileId - the file id
        Returns:
        an file's mime type, or null if no file has been uploaded
      • getSelectedFiles

        @Deprecated
        public List<WMultiFileWidget.FileWidgetUpload> getSelectedFiles()
        Deprecated.
        no longer required as unselected files are now removed. So all files are "selected".
        Returns only the selected file items. The file is selected if the checkbox adjacent to the uploaded file name is checked by the user.
        Returns:
        The uploaded file items that have been selected by the user. If no files have been selected then an empty list is returned.
      • isSelected

        @Deprecated
        public boolean isSelected​(File upload)
        Deprecated.
        no longer required as unselected files are now removed. So all files are "selected".
        Indicates whether the given upload has been selected by the user.
        Parameters:
        upload - the uploaded file
        Returns:
        true if the upload has been selected, false otherwise.
      • clearFiles

        public void clearFiles()
        Clear uploaded files from this component.
      • setFileTypes

        public void setFileTypes​(String[] types)
        Set each file type to be accepted by the WMultiFileWidget.
        Parameters:
        types - The file types that will be accepted by the file input.
        See Also:
        for the file types
      • setFileTypes

        public void setFileTypes​(Collection<String> types)
        Determines the file types accepted by this widget. Note that duplicates are not allowed and these are not case sensitive.
        The file type(s) can be either:
        • MIME type
        • Extension
        MIME type: it is type/subtype, where type is text, image, application etc, and subtype is plain, jpeg, * etc. Some example MIME types are:
        • text/* - indicates that all text files MIME types are accepted, text/html, text/plain etc.
        • image/jpeg - indicates that only jpeg image files are accepted.
        Setting mime type is more reliable, as the contents of the file is validated against accepted list.
        Extension: A string whose first character is a "." (U+002E) character (Indicates that files with the specified file extension are accepted). Some example extensions are:
        • .txt - indicates any files with extension txt are accepted.
        • .jpg - indicates any files with extension jpg are accepted.
        Setting extension is less reliable, as only the extension of uploaded file (if available) is validated against accepted list.
        Parameters:
        types - The file types that will be accepted by the file input. Note that this is not additive, it will overwrite any previously set fileTypes. Pass null or and empty collection to clear all file types.
      • setMaxFileSize

        public void setMaxFileSize​(long bytes)
        Set the maximum file size (in bytes) that will be accepted by the file input. If the user selects a file larger than this value the client script will tell the user it cannot be uploaded.
        Parameters:
        bytes - The maximum size (in bytes) that can be uploaded by this input.
      • getMaxFileSize

        public long getMaxFileSize()
        Return the maximum file size (in bytes) that can be accepted by this file input.
        Returns:
        The maximum size (in bytes) that can be uploaded by this component.
      • hasMaxFileSize

        public boolean hasMaxFileSize()
        Returns:
        true if max file size is supplied.
        See Also:
        setMaxFileSize(long)
      • getMaxFiles

        public int getMaxFiles()
        Return the maximum number of files that can be accepted by this file input.
        Returns:
        The maximum number of files that can be uploaded by this component.
      • setMaxFiles

        public void setMaxFiles​(int maxFiles)
        Set the maximum number of files that will be accepted by the file input.
        Parameters:
        maxFiles - The maximum number of files that can be uploaded by this input.
      • setDropzone

        public void setDropzone​(DropZone dropzone)
        Register a component to receive drag and dropped files on behalf of this input. It is recommended that you register the WApplication as the dropzone. This allows users to drop files anywhere on the page and eliminates the risk of them dropping files outside of the dropzone (which causes the browser to attempt to render the dropped files).
        Parameters:
        dropzone - The dropzone.
      • getDropzone

        public DropZone getDropzone()
        Return the dropzone associated with this file input.
        Returns:
        The dropzone or null if not set.
      • setEditor

        public void setEditor​(WImageEditor editor)
        Registers an image editor with this file upload widget so that the user will be prompted to edit (crop, rotate etc). This obviously only makes sense if this widget is configured to only allow image file types. It is probably also a logical idea to set max files to one.
        Parameters:
        editor - The image editor.
      • getEditor

        public WImageEditor getEditor()
        Return the image editor associated with this file input.
        Returns:
        The editor or null if not set.
      • setFileAjaxAction

        public void setFileAjaxAction​(Action action)
        The AJAX action used when an uploaded file has been selected.

        Setting this action causes the uploaded file links to act as AJAX triggers. The file id of the selected file is set as the action object.

        Parameters:
        action - the file AJAX action
      • getFileAjaxAction

        public Action getFileAjaxAction()
        The AJAX action used when an uploaded file has been selected.
        Returns:
        the file AJAX action
      • setColumns

        public void setColumns​(Integer cols)
        Sets the layout of uploaded files to be a certain number of columns. Null uses the theme default.
        Parameters:
        cols - the number of columns.
      • getColumns

        public Integer getColumns()
        Returns:
        the number of columns for layout of uploaded files. Null uses the theme default.
      • isNewUpload

        protected boolean isNewUpload()
        Used in handle request processing to trigger on change processing.
        Returns:
        true if a new file has been uploaded
      • setNewUpload

        public void setNewUpload​(boolean newUpload)
        Parameters:
        newUpload - true if a new file has been uploaded
      • isUseThumbnails

        public boolean isUseThumbnails()
        Returns:
        true if generate thumb nails for the file links.
      • setUseThumbnails

        public void setUseThumbnails​(boolean useThumbnails)
        If enabled then uploaded files will display to the user as thumbnails. While this can be used for any file types it is only recommended when the WMultiFileWidget is set to accept image types only, e.g. with setFileTypes(new String[] { "image/*" });
        Parameters:
        useThumbnails - true if generate thumb nails for the file links.
      • getThumbnailPosition

        public WLink.ImagePosition getThumbnailPosition()
        Returns:
        the position of the thumbnail image on the file link
      • setThumbnailPosition

        public void setThumbnailPosition​(WLink.ImagePosition thumbnailPosition)
        The position of the thumbnail image on the file link.

        If no position is set then the text is not shown.

        Parameters:
        thumbnailPosition - the position of the image
      • getThumbnailSize

        public Dimension getThumbnailSize()
        Retrieve the thumbnail size. If null, the default size is used.
        Returns:
        the thumbnail size or null for default
      • setThumbnailSize

        public void setThumbnailSize​(Dimension thumbnailSize)
        Set the thumbnail size. Null uses the default size.

        To scale thumbnails to a certain height or width, use -1 on the scalable dimension. For example, to scale thumbnails to 64 pixels high but maintain the correct width ration, set Height to 64 and Width to -1.

        Parameters:
        thumbnailSize - the thumbnail size or null for default
      • clearThumbnails

        public void clearThumbnails()
        Clear the thumbnails currently set on the files. This will cause them to be generated again when requested. This can be used if the thumbnail size has changed.
      • doHandleRequest

        protected boolean doHandleRequest​(Request request)
        Specific handle request processing for an input component is provided here.

        Input components are required to determine if the component has changed in the request, set the component data to the new value (if changed) and return the changed flag.

        Specified by:
        doHandleRequest in class AbstractInput
        Parameters:
        request - the request being responded to.
        Returns:
        true if the input component has changed, otherwise return false
      • getRequestValue

        public List<WMultiFileWidget.FileWidgetUpload> getRequestValue​(Request request)
        Provide the value of the component on the Request.

        If the component is not on the request, the components current value will be provided.

        Specified by:
        getRequestValue in interface Input
        Parameters:
        request - the request being responded to.
        Returns:
        the value of this component on the Request, or its current state if it is not on the request.
      • afterPaint

        protected void afterPaint​(RenderContext renderContext)
        Subclasses may override this method to output content after the component has been painted. When overriding this method, it is good practice to call the superclass implementation before emitting any additional content.
        Overrides:
        afterPaint in class AbstractWComponent
        Parameters:
        renderContext - the context to render to.
      • beforeHandleRequest

        protected boolean beforeHandleRequest​(Request request)
        Handle before handle request processing.
        Overrides:
        beforeHandleRequest in class AbstractInput
        Parameters:
        request - the request being responded to.
        Returns:
        true to continue
      • doHandleFileAjaxActionRequest

        protected void doHandleFileAjaxActionRequest​(Request request)
        Handle a file action AJAX request.
        Parameters:
        request - the request being processed
      • doHandleTargetedRequest

        protected void doHandleTargetedRequest​(Request request)
        Handle a targeted request. Can be a file upload, thumbnail request or file content request.
        Parameters:
        request - the request being processed
      • doHandleUploadRequest

        protected void doHandleUploadRequest​(Request request)
        The request is a targeted file upload request. Upload the file and respond with the file information.
        Parameters:
        request - the request being processed.
      • doHandleThumbnailRequest

        protected void doHandleThumbnailRequest​(WMultiFileWidget.FileWidgetUpload file)
        Handle the thumb nail request.
        Parameters:
        file - the file to process
      • doHandleFileContentRequest

        protected void doHandleFileContentRequest​(WMultiFileWidget.FileWidgetUpload file)
        Handle the file content request.
        Parameters:
        file - the file to process
      • createThumbNail

        protected Image createThumbNail​(File file)
        Parameters:
        file - the file to create a thumbnail for
        Returns:
        the thumbnail
      • getFileUrl

        public String getFileUrl​(String fileId)
        Retrieves a URL for the uploaded file content.
        Parameters:
        fileId - the file id
        Returns:
        the URL to access the uploaded file.
      • getFileThumbnailUrl

        public String getFileThumbnailUrl​(String fileId)
        Retrieves a URL for the thumbnail of an uploaded file.
        Parameters:
        fileId - the file id
        Returns:
        the URL to access the thumbnail for an uploaded file.
      • getTargetId

        public String getTargetId()
        The target id returned must be unique across all targetable WComponents within the application. In a portal environment, the target ids must also be unique across portlets. Most components should just return their component id.
        Specified by:
        getTargetId in interface Targetable
        Returns:
        the target id for this targetable.
      • getFileUploadRequestId

        public String getFileUploadRequestId()
        This method is used by the renderer to return the successful upload response.
        Returns:
        the file id that has been successfully uploaded, or null
      • getOrCreateComponentModel

        protected WMultiFileWidget.MultiFileWidgetModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class AbstractInput
        Returns:
        the model for this component