readTXTFile no dialog popup

I am getting the following error in web client with the readTXTfile, see the server log ( version 6.0.3) plus there is no dialog pop up I assume due to the error. When this code is run in developer in web client it works fine :

var txt = plugins.file.readTXTFile() 

java.awt.HeadlessException
at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source)
at java.awt.Window.(Unknown Source)
at java.awt.Frame.(Unknown Source)
at java.awt.Frame.(Unknown Source)
at javax.swing.SwingUtilities$SharedOwnerFrame.(Unknown Source)
at javax.swing.SwingUtilities.getSharedOwnerFrame(Unknown Source)
at javax.swing.JOptionPane.getRootFrame(Unknown Source)
at javax.swing.JOptionPane.getWindowForComponent(Unknown Source)
at javax.swing.JFileChooser.createDialog(Unknown Source)
at javax.swing.JFileChooser.showDialog(Unknown Source)
at javax.swing.JFileChooser.showOpenDialog(Unknown Source)
at com.servoy.j2db.util.FileChooserUtils.getAReadFile(FileChooserUtils.java:170)
at com.servoy.j2db.util.FileChooserUtils.getAReadFile(FileChooserUtils.java:160)
at com.servoy.extensions.plugins.file.FileProvider.js_readTXTFile(Unknown Source)
at com.servoy.extensions.plugins.file.WebFileProvider.js_readTXTFile(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:367)
at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:3666)
at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2680)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:166)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:387)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3134)
at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:165)
at com.servoy.j2db.scripting.ScriptEngine.executeFunction(ScriptEngine.java:528)
at com.servoy.j2db.FormController.executeFunction(FormController.java:4058)
at com.servoy.j2db.FormController.executeFunction(FormController.java:3937)
at com.servoy.j2db.FormController.executeFunction(FormController.java:3859)
at com.servoy.j2db.FormController$ScriptExecuter.executeFunction(FormController.java:3714)
at com.servoy.j2db.ui.BaseEventExecutor.fireEventCommand(BaseEventExecutor.java:271)
at com.servoy.j2db.ui.BaseEventExecutor.fireActionCommand(BaseEventExecutor.java:217)
at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor.onEvent(WebEventExecutor.java:401)
at com.servoy.j2db.server.headlessclient.dataui.WebEventExecutor$2.onEvent(WebEventExecutor.java:173)
at org.apache.wicket.ajax.AjaxEventBehavior.respond(AjaxEventBehavior.java:177)
at org.apache.wicket.ajax.AbstractDefaultAjaxBehavior.onRequest(AbstractDefaultAjaxBehavior.java:302)
at org.apache.wicket.request.target.component.listener.BehaviorRequestTarget.processEvents(BehaviorRequestTarget.java:157)
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92)
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1252)
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1331)
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1438)
at org.apache.wicket.RequestCycle.request(RequestCycle.java:546)
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:486)
at com.servoy.j2db.server.servlets.Zl.doGet(Zl.java:8)
at org.apache.wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:138)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)

ffow,

To get a file selection dialog in the webclient, use plugins.file.showFileOpenDialog(), see viewtopic.php?f=3&t=17457

Rob

I created a callbackmethod in my globals which is called but how do I then read the file ?
If I extract the file name from arguments[0] and add that to the following:

var txt = plugins.file.readTXTFile(filen)

When I test the above in developer and run the web client it still opens yet another dialog for the readTXTFile.

You can adjust this code which is for getting multiple files - once (filelist) has been passed to the Callback function the contents can be read into vars or your data table.

Also see the Wiki - https://wiki.servoy.com:8443/display/public/DOCS/file

function btnUpload(event){
  plugins.file.showFileOpenDialog(openFile_CALLBACK)
}

function openFile_CALLBACK(fileList){
for (var i = 0; i < fileList.length; i++) {
  application.output(fileList[i].getName() + ", " + fileList[i].getContentType())
}
}

Thanks but maybe Iam missing the obvious … theshowFileOpenDialog opens a dialog and has a button that says “upload”. Where is the file uploaded to as I cannot find it after I hit the button (done a search of the entire Servoy install folder).

Also as I mentioned above how do I read the contents of the file ? When I try var txt = plugins.file.readTXTFile(filen) and run this in Developer web client another dialog requesting the user select the file is opened, my interpretation of the wiki is that this should only occur if the filename is not there but not if web client.

The output from your code is “app1.csv, text/csv” and app1.csv is the file name then if I plug this into this code as var txt = plugins.file.readTXTFile(‘app1.csv’) it still opens a dialog, surely it needs the full path on the client to find the file ?

Here is the code I use.

In this instance I have created a new empty record in my Documents table with fields doc_filesize, doc_filename etc. Once you have selected and uploaded the file you need plugins.file.convertToJSFile

The client added a restriction so that only .doc/.docx/.xls/.xlxs/.pdf files could be uploaded.

function b_selectDocument(event) {
	//	110619
	plugins.file.showFileOpenDialog(1, null, false, null, b_AddDoc_FileSaveToDB, 'Select your File');
}

/**
 * @properties={typeid:24,uuid:"E4983149-37D0-4B22-A462-FE76F31183B0"}
 */
function b_AddDoc_FileSaveToDB(file)	{
	var vMedia = file[0];
	if (file){
		var vFile = plugins.file.convertToJSFile(file[0]);
		
		//	111025
		var vName	= vFile.getName();;
		var vIndex	= vName.lastIndexOf(".");
		var vExtn	= vName.substring(vIndex+1);
		
		//	111028 limit to accepted filetype - highlight bad EXT and return
		if (vExtn != 'doc' && vExtn != 'docx' && vExtn != 'xls' && vExtn != 'xlsx' && vExtn != 'pdf')	{
			elements.LBL_DocType.bgcolor	= '#ff1723';
			elements.LBL_DocType.fgcolor	= '#ffffff';
			return;
		}

			doc_filesize	= vFile.size()/1000;
			doc_fileblob	= vFile.getBytes();				
			doc_filename	= vFile.getName();			
			doc_name		= vFile.getName();
			doc_filetype	= vFile.getContentType();		
			xcreatedate	= new Date();

		getImage();			//	get correct image for XLS/DOC etc
		databaseManager.saveData();	
	}
}

HTH

Thanks again but when I try the above code the contents of the variable vFile is “UploadData[name:app1.csv,contenttype:text/csv]”

I copied that out of debug after this line was executed var vFile = plugins.file.convertToJSFile(file[0]);

If the content of the app1.csv file is “123,abc,deef,gij” how do I get those contents loaded into a variable so I can do something with whats in the file ? The file has not been saved in my Servoy install folder if its supposed to be either.

Ok got it now just needed to go :

var txt = plugins.file.readTXTFile(vFile)

Thanks for your help.