com.smartgwt.client.widgets.form.fields
Class UploadItem

java.lang.Object
  extended by com.smartgwt.client.core.JsObject
      extended by com.smartgwt.client.core.DataClass
          extended by com.smartgwt.client.core.RefDataClass
              extended by com.smartgwt.client.widgets.form.fields.FormItem
                  extended by com.smartgwt.client.widgets.form.fields.TextItem
                      extended by com.smartgwt.client.widgets.form.fields.UploadItem
All Implemented Interfaces:
HasHandlers, HasBlurHandlers, HasChangedHandlers, HasChangeHandlers, HasClickHandlers, HasDoubleClickHandlers, HasEditorEnterHandlers, HasEditorExitHandlers, HasFocusHandlers, HasIconClickHandlers, HasIconKeyPressHandlers, HasItemHoverHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasPickerIconClickHandlers, HasTitleClickHandlers, HasTitleDoubleClickHandlers, HasTitleHoverHandlers

public class UploadItem
extends TextItem

FormItem that creates an HTML <input type="upload"> control, with an interface that allows a user to pick a file from his machine to upload to the server.

NOTE: use FileItem, not UploadItem, if you are using the Smart GWT Server framework. FileItem is much easier to use and addresses all the limitations of UploadItem discussed below. See the Uploading Files overview for details.

If a form containing an UploadItem is redrawn (which may happen if other form items are shown or hidden, the form is resized, or other items show validation errors) then the value in the upload item is lost (because an HTML upload field may not be created with a value). For this reason, if you are building a form that combines an UploadItem with other FormItems that could trigger redraw()s, recommended practice is to place each UploadItem in a distinct DynamicForm instance and create the visual appearance of a single logical form via combining the DynamicForms in a Layout.

NOTE: Browser-specific behaviors:

See Also:
Upload overview and related methods

Field Summary
 
Fields inherited from class com.smartgwt.client.core.JsObject
jsObj
 
Constructor Summary
UploadItem()
           
UploadItem(JavaScriptObject jsObj)
           
UploadItem(String name)
           
UploadItem(String name, String title)
           
 
Method Summary
 Boolean getMultiple()
          When true, allow the file-selection dialog shelled by the browser to select multiple files.
static UploadItem getOrCreateRef(JavaScriptObject jsObj)
           
 void setJavaScriptObject(JavaScriptObject jsObj)
           
 void setMultiple(Boolean multiple)
          When true, allow the file-selection dialog shelled by the browser to select multiple files.
 void setValue()
          Attempting to set the value for an upload form item is disallowed for security reasons.
 
Methods inherited from class com.smartgwt.client.widgets.form.fields.TextItem
deselectValue, deselectValue, getChangeOnKeypress, getCharacterCasing, getEnteredValue, getFormatOnFocusChange, getHeight, getHint, getKeyPressFilter, getLength, getMask, getMaskOverwriteMode, getMaskPadChar, getMaskPromptChar, getMaskSaveLiterals, getPrintFullText, getSaveOnEnter, getSelectionRange, getSelectOnFocus, getShowHintInField, getTextBoxStyle, getValueAsString, getWidth, selectValue, setChangeOnKeypress, setCharacterCasing, setFormatOnFocusChange, setHeight, setKeyPressFilter, setLength, setMask, setMaskOverwriteMode, setMaskPadChar, setMaskPromptChar, setMaskSaveLiterals, setPrintFullText, setSaveOnEnter, setSelectionRange, setSelectOnFocus, setShowHintInField, setTextBoxStyle, setWidth
 
Methods inherited from class com.smartgwt.client.widgets.form.fields.FormItem
_getValue, addBlurHandler, addChangedHandler, addChangeHandler, addClickHandler, addDoubleClickHandler, addEditorEnterHandler, addEditorExitHandler, addFocusHandler, addIconClickHandler, addIconKeyPressHandler, addItemHoverHandler, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addPickerIconClickHandler, addTitleClickHandler, addTitleDoubleClickHandler, addTitleHoverHandler, blurItem, canEditCriterion, clearValue, convertToFormItemArray, disable, enable, focusInItem, getAccessKey, getAlign, getAllowExpressions, getAlwaysFetchMissingValues, getAttribute, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsFloat, getAttributeAsInt, getAttributeAsJavaScriptObject, getAttributeAsString, getBrowserSpellCheck, getCanEdit, getCanFocus, getCellHeight, getCellStyle, getClassName, getConfig, getContainerWidget, getCriteriaField, getCriterion, getCriterion, getDataPath, getDateFormatter, getDecimalPad, getDecimalPrecision, getDefaultIconSrc, getDisabled, getDisableIconsOnReadOnly, getDisplayField, getDisplayFieldName, getDisplayValue, getDisplayValue, getEditorTypeConfig, getEditPendingCSSText, getEmptyDisplayValue, getEmptyValueIcon, getEndRow, getErrorIconHeight, getErrorIconSrc, getErrorIconWidth, getErrorMessageWidth, getFetchMissingValues, getFieldName, getFilterLocally, getForm, getFullDataPath, getGlobalTabIndex, getHintStyle, getHoverAlign, getHoverDelay, getHoverHeight, getHoverOpacity, getHoverStyle, getHoverVAlign, getHoverWidth, getIcon, getIconHeight, getIconPageRect, getIconPrompt, getIconRect, getIconVAlign, getIconWidth, getImageURLPrefix, getImageURLSuffix, getImplicitSave, getImplicitSaveOnBlur, getInputFormat, getLeft, getLocateItemBy, getMultipleValueSeparator, getName, getOperator, getOptionCriteria, getOptionFilterContext, getOptionOperationId, getPageLeft, getPageRect, getPageTop, getPickerIconHeight, getPickerIconName, getPickerIconPrompt, getPickerIconSrc, getPickerIconWidth, getPrintTextBoxStyle, getPrintTitleStyle, getPrompt, getRect, getRedrawOnChange, getRejectInvalidValueOnChange, getRequired, getRequiredMessage, getRowSpan, getSelectedRecord, getShouldSaveValue, getShowDisabled, getShowErrorIcon, getShowErrorStyle, getShowErrorText, getShowFocused, getShowFocusedIcons, getShowFocusedPickerIcon, getShowHint, getShowIcons, getShowOverIcons, getShowPickerIcon, getShowTitle, getShowValueIconOnly, getStartRow, getStopOnError, getSuppressValueIcon, getSynchronousValidation, getTabIndex, getTextAlign, getTimeFormatter, getTitle, getTitleAlign, getTitleColSpan, getTitleOrientation, getTitleStyle, getTitleVAlign, getTooltip, getTop, getType, getValidateOnChange, getValidateOnExit, getValidOperators, getVAlign, getValue, getValueField, getValueFieldName, getValueIconHeight, getValueIconLeftPadding, getValueIconRightPadding, getValueIconSize, getValueIconWidth, getVisible, getVisibleHeight, getVisibleWidth, getWrapTitle, hasAdvancedCriteria, hide, hideIcon, invalidateDisplayValueCache, isCreated, isDisabled, isDrawn, isVisible, redraw, setAccessKey, setAlign, setAllowExpressions, setAlwaysFetchMissingValues, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setBrowserSpellCheck, setCanEdit, setCanEditCriterionPredicate, setCanFocus, setCellHeight, setCellStyle, setColSpan, setColSpan, setCriteriaField, setCriterion, setCriterionGetter, setCriterionSetter, setDataPath, setDateFormatter, setDecimalPad, setDecimalPrecision, setDefaultIconSrc, setDefaultValue, setDefaultValue, setDefaultValue, setDefaultValue, setDefaultValue, setDisabled, setDisableIconsOnReadOnly, setDisplayField, setDisplayFormat, setDisplayFormat, setEditorType, setEditorValueFormatter, setEditorValueParser, setEditPendingCSSText, setEmptyDisplayValue, setEmptyValueIcon, setEndRow, setErrorFormatter, setErrorIconHeight, setErrorIconSrc, setErrorIconWidth, setErrorMessageWidth, setErrorOrientation, setFetchMissingValues, setFilterLocally, setGlobalTabIndex, setHeight, setHint, setHintStyle, setHoverAlign, setHoverDelay, setHoverHeight, setHoverOpacity, setHoverStyle, setHoverVAlign, setHoverWidth, setIconHeight, setIconPrompt, setIcons, setIconVAlign, setIconWidth, setImageURLPrefix, setImageURLSuffix, setImplicitSave, setImplicitSaveOnBlur, setInitHandler, setInputFormat, setInputTransformer, setItemHoverFormatter, setItemTitleHoverFormatter, setLeft, setLocateItemBy, setMultipleValueSeparator, setName, setOperator, setOptionCriteria, setOptionDataSource, setOptionFilterContext, setOptionOperationId, setPickerIconHeight, setPickerIconName, setPickerIconPrompt, setPickerIconSrc, setPickerIconWidth, setPrintTextBoxStyle, setPrintTitleStyle, setPrompt, setProperty, setProperty, setProperty, setProperty, setProperty, setRedrawOnChange, setRedrawOnChange, setRejectInvalidValueOnChange, setRequired, setRequiredMessage, setRowSpan, setShouldSaveValue, setShowDisabled, setShowErrorIcon, setShowErrorStyle, setShowErrorText, setShowFocused, setShowFocusedIcons, setShowFocusedPickerIcon, setShowHint, setShowIcons, setShowIfCondition, setShowOverIcons, setShowPickerIcon, setShowTitle, setShowValueIconOnly, setStartRow, setStopOnError, setSuppressValueIcon, setSynchronousValidation, setTabIndex, setTextAlign, setTimeFormatter, setTitle, setTitleAlign, setTitleColSpan, setTitleOrientation, setTitleStyle, setTitleVAlign, setTooltip, setTop, setType, setValidateOnChange, setValidateOnExit, setValidators, setValidOperators, setVAlign, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueField, setValueFormatter, setValueIconHeight, setValueIconLeftPadding, setValueIconMapper, setValueIconRightPadding, setValueIcons, setValueIconSize, setValueIconWidth, setValueMap, setValueMap, setVisible, setWidth, setWrapTitle, shouldFetchMissingValue, shouldSaveOnEnter, show, showIcon, showPicker, stopHover, updateState, validate
 
Methods inherited from class com.smartgwt.client.core.RefDataClass
getRef, getRef
 
Methods inherited from class com.smartgwt.client.core.DataClass
doAddHandler, fireEvent, getAttributeAsDoubleArray, getAttributeAsIntArray, getAttributeAsLong, getAttributeAsMap, getAttributeAsObject, getAttributeAsRecord, getAttributeAsStringArray, getAttributes, getHandlerCount, getJsObj, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute
 
Methods inherited from class com.smartgwt.client.core.JsObject
setJsObj
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Constructor Detail

UploadItem

public UploadItem()

UploadItem

public UploadItem(JavaScriptObject jsObj)

UploadItem

public UploadItem(String name)

UploadItem

public UploadItem(String name,
                  String title)
Method Detail

getOrCreateRef

public static UploadItem getOrCreateRef(JavaScriptObject jsObj)

setJavaScriptObject

public void setJavaScriptObject(JavaScriptObject jsObj)
Overrides:
setJavaScriptObject in class TextItem

setMultiple

public void setMultiple(Boolean multiple)
When true, allow the file-selection dialog shelled by the browser to select multiple files.

Support is not full-cycle at the server - that is, there are server APIs for retrieving each file that was uploaded, but no built-in support for storing multiple files against a single DataSource field. However, you can write custom server DMI code to do something with the files - for instance, you could create multiple new DataSource records for each file via a server DMI like this below:

     String fileNameStr = (String)dsRequest.getValues().get("image_filename").toString();
 
     String[] fileNames = fileNameStr.split(", ");
     List files = dsRequest.getUploadedFiles();
 
     for (int i = 0; i < files.size(); i++) {
         ISCFileItem file = (ISCFileItem)files.get(i);
         InputStream fileData = file.getInputStream();
         DSRequest inner = new DSRequest("mediaLibrary", "add");
         Map values = new HashMap();
         values.put("title", dsRequest.getValues().get("title"));
         values.put("image", fileData);
         values.put("image_filename", fileNames[i]);
         values.put("image_filesize", file.getSize());
         values.put("image_date_created", new Date());
         
         inner.setValues(values);
         inner.execute();
     }
     
     DSResponse dsResponse = new DSResponse();
     
     dsResponse.setStatus(0);
 
     return dsResponse;
  

Parameters:
multiple - multiple Default value is true

getMultiple

public Boolean getMultiple()
When true, allow the file-selection dialog shelled by the browser to select multiple files.

Support is not full-cycle at the server - that is, there are server APIs for retrieving each file that was uploaded, but no built-in support for storing multiple files against a single DataSource field. However, you can write custom server DMI code to do something with the files - for instance, you could create multiple new DataSource records for each file via a server DMI like this below:

     String fileNameStr = (String)dsRequest.getValues().get("image_filename").toString();
 
     String[] fileNames = fileNameStr.split(", ");
     List files = dsRequest.getUploadedFiles();
 
     for (int i = 0; i < files.size(); i++) {
         ISCFileItem file = (ISCFileItem)files.get(i);
         InputStream fileData = file.getInputStream();
         DSRequest inner = new DSRequest("mediaLibrary", "add");
         Map values = new HashMap();
         values.put("title", dsRequest.getValues().get("title"));
         values.put("image", fileData);
         values.put("image_filename", fileNames[i]);
         values.put("image_filesize", file.getSize());
         values.put("image_date_created", new Date());
         
         inner.setValues(values);
         inner.execute();
     }
     
     DSResponse dsResponse = new DSResponse();
     
     dsResponse.setStatus(0);
 
     return dsResponse;
  

Returns:
Boolean

setValue

public void setValue()
Attempting to set the value for an upload form item is disallowed for security reasons. Therefore this method will just log a warning, and not modify the value of the item.