File Chooser Widget

File Chooser provides a way of choosing files from the desktop. The widget uses Prototype library and implements DWR (Direct Web Remoting) to get data.

Dependency

Depends on Location Chooser

Features

  • Select single/multiple files
  • Dialog and inline mode
  • Return selected value in the textfield

How to use

Add this code to the head section of the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<style type="text/css" title="currentStyle" media="screen">
 @import '<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request, "theme","app","css.jsp?externalApp=true")%>';
</style>
<script src='/dekohportal/dwr/engine.js'></script>
<script src='/dekohportal/dwr/util.js'></script>
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request, "common",null,"JSlibrary.jsp")%>"></script>
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request, "widget","dialog","dialog.js")%>"></script>
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request, "widget","fileChooser","fileChooserDialog.js")%>"></script>
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request, "widget","locationChooser","locationchooser.js")%>"></script>
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request, "widget","fileChooser","filechooser.js")%>"></script>
<script src='/dekohportal/dwr/interface/locationchooser.js'>
</script>

JavaScript code

The basic syntax to initialize the Dialog widget is
<script type="text/javascript">
function handleLocationChooserOnClose(gDialogId, returnValue, servletUrl)
{
  alert('selected folder is '+returnValue);
}
</script>
<script type="text/javascript">
function openFilesDialog(){
new LC_Dialog('dialog_ID',{ returnTxtFieldId:'chosenFiles', fileSeperator:'\\', multiSelect:true });
}
</script>

HTML code

Include the following code where you want to invoke the File Chooser in page:

<input type="text" size="30" id="chosenFiles" name="chosenFiles" value=""/>
<input type="button" value="Select Files" onclick="javascript:openFilesDialog();"/>

Embedding the File Chooser in the page

Add this code to the head section of the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<style type="text/css" title="currentStyle" media="screen">
 @import '<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request, "theme","app","css.jsp?externalApp=true")%>';
</style>
<script src='/dekohportal/dwr/engine.js'></script>
<script src='/dekohportal/dwr/util.js'></script>
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request,"common",null,"JSlibrary.jsp")%>"></script>
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request,"widget","dialog","dialog.js")%>"></script>
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request,"widget","fileChooser","fileChooserDialog.js")%>"></script>      
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request,"widget","fileChooser","filechooser.js")%>"></script>
<script type="text/javascript" src="<%=dekoh.portal.util.StaticFilesURLGenerator.generateStaticFileURL(request,"widget","locationChooser","locationchooser.js")%>"></script>    
<script src='/dekohportal/dwr/interface/locationchooser.js'></script>

Javascript code

The basic syntax to initialize the Dialog widget is

<script type="text/javascript">
function showFileChooser(){
var strContent = '<div id="fileChooserDiv"></div>';
var oFileChooserDialog = new dekohDialog(gDialogId, {className:'greylighting',title:"Import",height:450,width:600,resizable:false,maximizable:false,minimizable:false,content:strContent});
new FileChooser('fileChooser',{targetDivId:'fileChooserDiv',mode:'select',returnTxtFieldId:'',trayObjRef:oFileChooserDialog,fileFilter:'photos',fileSeperator:'\\', multiSelect:true});
}
</script>
<script type="text/javascript">
function trayFileChooser(gDialogId, returnValue, servletUrl){
alert('selected folder is '+returnValue);
}
</script>

HTML Code

Include this code in the page:
<div id="fileChooserDiv"></div>
<input type="text" size="30" id="chosenFiles" name="chosenFiles" value=""/>
<input type="button" value="Show File Chooser" onclick="javascript:showFileChooser();"/>

Parameters for initializing the widget

Required parameters

OptionsSinceDescriptionDefault
IdV1.0Dialog Id-

Optional parameters

OptionsSinceDescriptionDefault
targetDivIdV1.0The target division Id where the file chooser is going to get loadednull
modeV1.0Start the dialog in ‘select’ or ‘save’ mode'select'
returnTxtFieldIdV1.0When the dialog is initialized in the select mode the values are returned to the text field element idnull
trayObjRefV1.0The Object reference of the traynull
fileFilterV1.0Set the file name filter to show in the populated list‘*’
fileExtensionsV1.0Set the filters of the file extensions which have to show in the list. Eg ‘.gif’,’.doc’‘*.*’
fileSeperatorV1.0This value is to be initialized for different operating systems
multiSelectV1.0Set the value as true or false for enabling multiple file selectiontrue

Functions

FunctionParametersDescription
fillFilterOptions--
createFileListtargetEle:Target Element to Render, fullTree:Current tree object,currentPath:Current clicked pathThis creates file list from the selection
applyFileTypeFilter--
applyFileNameFilter--
setCurrentFile--
selectFiles--

Parameters for running File Chooser in dialog mode

Required parameters

OptionsSinceDescriptionDefault
IdV1.0Dialog Id-

Optional parameters

OptionsSinceDescriptionDefault
classNameV1.0The style classDekoh
returnTxtFieldIdV1.0When the dialog is initialized in the select mode the values are returned to the text field element id
modeV1.0Start the dialog in ‘select’ or ‘save’ modeselect
trayTopMessageV1.0The message shown on the dialog“Select file(s) to add/import”
fileSeperatorV1.0This value is to be initialized for different operating systems
multiSelectV1.0Set the value as true or false for enabling multiple file selectiontrue
titleV1.0Set the title here‘File Chooser’
widthV1.0Width of the dialog600
heightV1.0Height of the dialog450
xPosV1.0Specify the x position of the dialog in the document 0
yPosV1.0
minimizableV1.0
maximizableV1.0
isModalV1.0

DWR Implementation

Reference in web.xml

<init-param>
            <param-name>config-locationChooser</param-name>
            <param-value>widgets/locationChooser/dwr-locationchooser.xml</param-value>
</init-param>

DWR XML

<dwr>
    <allow>
        <create creator="new" javascript="locationchooser">
            <param name="class" 					value="dekoh.dekohportal.widget.locationchooser.LocationChooserUtil"/>
            <include method="getRootDirectories"/>
            <include method="saveLocationBookMark"/>
            <include method="saveFileBookMark"/>
            <include method="getAllLocationBookMarks"/>
            <include method="getAllFileBookMarks"/>
            <include method="getLocationBookMark"/>
            <include method="getFileBookMark"/>
            <include method="getCurrentFolderTree"/>
        </create>
        <convert converter="bean" match="dekoh.dekohportal.widget.locationchooser.LocationObject"/>
        <convert converter="bean" match="dekoh.dekohportal.widget.locationchooser.BookMarkObject"/>

    </allow>
</dwr>

Creators

Each class on which we execute methods, needs a <create ...> entry. There are several types of creator. The most common ones use either the 'new' keyword or the Spring framework. For more information, see the Creator documentation.

Methods-functionality

Method NameFunctionality
getRootDirectories-
saveLocationBookMark-
saveFileBookMark-
getAllLocationBookMarks-
getAllFileBookMarks-
getLocationBookMark-
getFileBookMark-
getCurrentFolderTree-

Converters

We need to ensure that all the parameters can be converted. Many of the types provided by the JDK are enabled for you, but you need to give DWR permission to convert your own code. Generally this means that JavaBean parameters will need a <convert ...> entry.

Availability

Dekoh Portal Ver 0.4.2 or later.

Attachments

filechooser_widget.jpg Info on filechooser_widget.jpg 129447 bytes