org.zkoss.zul
Class Fileupload

java.lang.Object
  extended by org.zkoss.zk.ui.AbstractComponent
      extended by org.zkoss.zk.ui.HtmlBasedComponent
          extended by org.zkoss.zul.Fileupload
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.sys.ComponentCtrl

public class Fileupload
extends org.zkoss.zk.ui.HtmlBasedComponent

A fileupload dialog used to let user upload a file.

There are two ways to use Fileupload:

1. Open as a modal dialog:

You don't create Fileupload directly. Rather, use get() or get(String, String).

2. Embed as part of the page:

You can create it as a component and then listen to the onUpload event (UploadEvent). If the cancel button is pressed or file(s) is uploaded, the onClose event (Event). is sent to notify the application. By default, it does nothing but invalidate the component, i.e., all fields are cleared.

A non-XUL extension.

Author:
tomyeh
See Also:
Filedownload, Serialized Form

Nested Class Summary
protected  class Fileupload.ExtraCtrl
          A utility class to implement AbstractComponent.getExtraCtrl().
 
Field Summary
 
Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent
RS_NO_DISPLAY, RS_NO_HEIGHT, RS_NO_WIDTH
 
Fields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
 
Constructor Summary
Fileupload()
           
 
Method Summary
static org.zkoss.util.media.Media get()
          Opens a modal dialog with the default message and title, and let user upload a file.
static org.zkoss.util.media.Media[] get(int max)
          Opens a modal dialog to upload mulitple files with the default message and title.
static org.zkoss.util.media.Media get(java.lang.String message, java.lang.String title)
          Opens a modal dialog with the specified message and title, and let user upload a file.
static org.zkoss.util.media.Media[] get(java.lang.String message, java.lang.String title, int max)
          Opens a modal dialog to upload multiple files with the specified message and title.
 int getNumber()
          Returns the maximal allowed number of files to upload.
static java.lang.String getTemplate()
          Returns the template used to create the upload modal dialog.
 boolean isChildable()
          No child is allowed.
protected  java.lang.Object newExtraCtrl()
           
 void onClose()
          Hanldes the onClose event which is sent when file(s) is uploaded or when the cancel button is pressed.
 void setNumber(int maxnum)
          Sets the maximal allowed number of files to upload.
static void setTemplate(java.lang.String uri)
          Sets the template used to create the upload modal dialog.
 
Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
addEventListener, appendAsapAttr, focus, getDraggable, getDroppable, getHeight, getInnerAttrs, getLeft, getOuterAttrs, getRealStyle, getRealStyleFlags, getSclass, getStyle, getTooltiptext, getTop, getWidth, getZIndex, isAsapRequired, removeEventListener, setClass, setDraggable, setDroppable, setHeight, setLeft, setSclass, setStyle, setTooltiptext, setTop, setWidth, setZIndex
 
Methods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addAnnotation, addEventHandler, addSharedAnnotationMap, addSharedEventHandlerMap, appendChild, applyProperties, clone, containsVariable, detach, equals, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttributes, getAttributes, getChildren, getDefinition, getDesktop, getEventHandler, getExtraCtrl, getFellow, getFellowIfAny, getId, getListenerIterator, getMold, getMoldURI, getNamespace, getPage, getParent, getPropagatee, getRoot, getSpaceOwner, getUuid, getVariable, insertBefore, invalidate, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onDrawNewChild, onWrongValue, redraw, removeAttribute, removeAttribute, removeChild, response, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setComponentDefinition, setId, setMold, setPage, setParent, setVariable, setVisible, smartUpdate, smartUpdate, smartUpdate, toString, unsetVariable
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Fileupload

public Fileupload()
Method Detail

isChildable

public boolean isChildable()
No child is allowed.

Specified by:
isChildable in interface org.zkoss.zk.ui.Component
Overrides:
isChildable in class org.zkoss.zk.ui.AbstractComponent

getNumber

public int getNumber()
Returns the maximal allowed number of files to upload.

Since:
2.4.0

setNumber

public void setNumber(int maxnum)
               throws org.zkoss.zk.ui.WrongValueException
Sets the maximal allowed number of files to upload.

Default: 1.

Throws:
org.zkoss.zk.ui.WrongValueException - if non-positive, or it exceeds 1000
Since:
2.4.0

onClose

public void onClose()
Hanldes the onClose event which is sent when file(s) is uploaded or when the cancel button is pressed.

By default, it simply invalidates itself, i.e., all fields are cleared. If you want to do something different, you can intercept the onClose event.

Since:
2.4.0

newExtraCtrl

protected java.lang.Object newExtraCtrl()
Overrides:
newExtraCtrl in class org.zkoss.zk.ui.HtmlBasedComponent

get

public static org.zkoss.util.media.Media get()
                                      throws java.lang.InterruptedException
Opens a modal dialog with the default message and title, and let user upload a file.

Returns:
the uploaded content, or null if not uploaded.
Throws:
java.lang.InterruptedException

get

public static org.zkoss.util.media.Media get(java.lang.String message,
                                             java.lang.String title)
                                      throws java.lang.InterruptedException
Opens a modal dialog with the specified message and title, and let user upload a file.

Parameters:
message - the message. If null, the default is used.
title - the title. If null, the default is used.
Returns:
the uploaded content, or null if not ready.
Throws:
java.lang.InterruptedException

get

public static org.zkoss.util.media.Media[] get(int max)
                                        throws java.lang.InterruptedException
Opens a modal dialog to upload mulitple files with the default message and title.

Parameters:
max - the maximal allowed number that an user can upload at once. If nonpositive, 1 is assumed.
Returns:
an array of files that an users has uploaded, or null if uploaded.
Throws:
java.lang.InterruptedException

get

public static org.zkoss.util.media.Media[] get(java.lang.String message,
                                               java.lang.String title,
                                               int max)
                                        throws java.lang.InterruptedException
Opens a modal dialog to upload multiple files with the specified message and title.

Parameters:
max - the maximal allowed number that an user can upload at once. If nonpositive, 1 is assumed. If max is larger than 1000, 1000 is assumed.
Returns:
an array of files that an users has uploaded, or null if uploaded.
Throws:
java.lang.InterruptedException

setTemplate

public static void setTemplate(java.lang.String uri)
Sets the template used to create the upload modal dialog.

The template must follow the default template: ~./zul/html/fileuploaddlg.zul

In other words, just adjust the label and layout and don't change the component's ID.

Note: the template has no effect, if you use Fileupload as a component (and embed it to a page).


getTemplate

public static java.lang.String getTemplate()
Returns the template used to create the upload modal dialog.



Copyright © 2005-2007 Potix Corporation. All Rights Reserved.