Try to run the update example,

Hi isomorphic,

I’m trying to run the update example (http://www.smartclient.com/#upload) but I have not been able to do it.

Here is my jsp code:

<%@ taglib uri="/WEB-INF/iscTaglib.xml" prefix="isomorphic" %>

<HTML>
	<HEAD>
	    <SCRIPT>var isomorphicDir="isomorphic/";</SCRIPT>
	    <SCRIPT SRC=isomorphic/system/modules/ISC_Core.js></SCRIPT>
	    <SCRIPT SRC=isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
	    <SCRIPT SRC=isomorphic/system/modules/ISC_Containers.js></SCRIPT>
	    <SCRIPT SRC=isomorphic/system/modules/ISC_Grids.js></SCRIPT>
	    <SCRIPT SRC=isomorphic/system/modules/ISC_Forms.js></SCRIPT>
	    <SCRIPT SRC=isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
	    <SCRIPT SRC=isomorphic/skins/TreeFrog/load_skin.js></SCRIPT>
	</HEAD>
	<BODY>
		<SCRIPT>

			<isomorphic:loadDS ID="uploadFile"/>

			var firstTime=true;
			
			isc.DynamicForm.create({
			    ID: "uploadForm",
			    dataSource: uploadFile,
			    fields: [
			        { name: "title" },
			        { name: "file", hint: "Maximum file-size is 50k" },
			        { title: "Save", type: "button", 
			            click: function () {
			                this.form.saveData(null, {params: {singleUpload: true}});
			                this.form.editNewRecord();
			            }
			        }
			    ]
			});
			
			isc.DynamicForm.create({
			    ID: "searchForm",
			    width: "100%",
			    numCols: 3,
			    colWidths: [60, 200, "*"],
			    saveOnEnter:true, 
			    fields: [
			        { name: "title", title: "Title", type: "text", width: "*" },
			        { name: "search", title: "Search", type: "SubmitItem",
			            startRow: false, endRow: false
			        }
			    ],
			    submit : function () {
			        mediaTileGrid.fetchData(this.getValuesAsCriteria(), null, {textMatchStyle:"substring"});
			    } 
			});
			
			isc.IButton.create({
			    ID: "viewAsTiles",
			    title: "View as Tiles",
			    autoFit: true,
			    value: true,
			    radioGroup: "views",
			    actionType: "checkbox",
			    click: function(){
			        showTileGrid();
			    }
			});
			
			isc.IButton.create({
			    ID:"viewAsList",
			    title: "View as List",
			    autoFit: true,
			    radioGroup: "views",
			    actionType: "checkbox",
			    click: function(){
			        showListGrid();
			    }
			});
			
			isc.HLayout.create({
			    ID: "buttons",
			    width: 500,
			    membersMargin: 5,
			    padding: 5,
			    members: [viewAsTiles, viewAsList]
			});
			
			isc.TileGrid.create({
			        ID: "mediaTileGrid",
			        width: "100%",
			        height: 224,
			        tileWidth: 100,
			        tileHeight: 150,
			        dataSource: uploadFile,
			        autoFetchData: true
			});
			
			isc.ListGrid.create({
			        ID: "mediaListGrid",
			        width: "100%",
			        height: 224,
			        alternateRecordStyles: true,
			        dataSource: uploadFile
			});
			
			isc.VLayout.create({
			    ID:"mainLayout",
			    left: 350,
			    width:500,
			    height:250,
			    members:[searchForm, buttons, mediaTileGrid, mediaListGrid]
			});
			
			viewAsTiles.click();
			
			function showTileGrid() {
			    mediaListGrid.hide();
			    mediaTileGrid.show();
			}
			
			function showListGrid() {
			    if (firstTime) {
			        firstTime = false;
			        mediaListGrid.setData(mediaTileGrid.getData());
			    }
			    mediaTileGrid.hide();
			    mediaListGrid.show();
			}
			
		</SCRIPT>
	</BODY>	
</HTML>

Here is my datasouce code:

<DataSource	
	ID="uploadFile" 
	serverType="generic">
	<fields>
        <field name="pk"    type="sequence" hidden="true" primaryKey="true"/>
        <field name="title" />
		<field name="file"  type="binary"   title="File" maxFileSize="51200" />
	</fields>
	
	<serverObject lookupStyle="new" className="dmi.UploadFileDMI"/>

</DataSource>

I use a bean in order to populate a listGrid, here is de bean code:

package model;

public class UploadFileVO {

	// public members
	public Integer pk;
	public String title;
	public byte[] file;
	
	public byte[] getFile() {
		return file;
	}
	public void setFile(byte[] file) {
		this.file = file;
	}
	public Integer getPk() {
		return pk;
	}
	public void setPk(Integer pk) {
		this.pk = pk;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
}

As you see the image is a binary (byte array).

Here is my dmi class code:

public class UploadFileDMI {

    Logger log = new Logger(UploadFileDMI.class.getName());

    public DSResponse fetch(DSRequest dsRequest) throws Exception {
    	
        log.info("procesing DMI fetch operation");

    	DSResponse dsResponse = new DSResponse();

    	long startRow = dsRequest.getStartRow();
    	long endRow = dsRequest.getEndRow();
    	
    	long totalRows = 1;
    	       
        // clamp endRow to available rows and slice out requested range
        endRow = Math.min(endRow, totalRows);

        
    	List<UploadFileVO> results = new ArrayList<UploadFileVO>();
    	
    	UploadFileVO uploadFileVO = new UploadFileVO();
    	
    	uploadFileVO.setPk(new Integer(0));
    	uploadFileVO.setTitle("Mi Archivo");
    	    	
    	File myFile = new File("MyFile.png");
    	uploadFileVO.setFile(BytesFromFile.getBytesFromFile(myFile));
    	
    	results.add(uploadFileVO);

    	
        // DataSource protocol: return matching item beans
        dsResponse.setData(results);
                
        // tell client what rows are being returned, and what's available
        dsResponse.setStartRow(startRow);
        dsResponse.setEndRow(endRow);
        dsResponse.setTotalRows(totalRows);

    	
    	return dsResponse;
    	
    }

I read the image with the folling code:

package util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class BytesFromFile {

	public static byte[] getBytesFromFile(File file) throws IOException {
        InputStream is = new FileInputStream(file);
    
        // Get the size of the file
        long length = file.length();
    
        if (length > Integer.MAX_VALUE) {
            // File is too large
        }
    
        // Create the byte array to hold the data
        byte[] bytes = new byte[(int)length];
    
        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length
               && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
            offset += numRead;
        }
    
        // Ensure all the bytes have been read in
        if (offset < bytes.length) {
            throw new IOException("Could not completely read file "+file.getName());
        }
    
        // Close the input stream and return bytes
        is.close();
        return bytes;
                
    } 	
	
}

When I call my jsp appears only the legend “Finding records that match your criteria…”.

I the firebug appears, in PRC tab – Request tab appear:

{
    actionURL:"http://localhost:8080/transporte/isomorphic/IDACall", 
    showPrompt:true, 
    prompt:"Finding records that match your criteria...", 
    transport:"xmlHttpRequest", 
    promptStyle:"dialog", 
    bypassCache:true, 
    data:{
        criteria:{
        }, 
        operationConfig:{
            dataSource:"uploadFile", 
            operationType:"fetch", 
            textMatchStyle:"exact"
        }, 
        startRow:0, 
        endRow:75, 
        componentId:"mediaTileGrid", 
        appID:"builtinApplication", 
        operation:"uploadFile_fetch", 
        oldValues:{
        }
    }
}

I the firebug appears, in PRC tab – Response tab appear:

[
    {
        invalidateCache:false,
        endRow:1,
        data:[
            {
                file:"‰PNG



binary data here




                pk:0,
                title:"Mi Archivo"
            }
        ],
        status:0,
        totalRows:1,
        startRow:0,
        isDSResponse:true
    }
]

I am using:

apache-tomcat-5.5.20
JDK 1.6
MyEclipse 5.1.1 GA
SmartClient_70rc2_Evaluation
Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.0.13)
Gecko/2009073022 Firefox/3.0.13 (.NET CLR 3.5.30729)

I am not able to display the grid, but previously I test only the upload and its run.

Please Help Me

In your DMI, don’t return binary data for an ordinary “fetch” request, just omit the binary field. Instead, return an OutputStream as the field value for the binary field when your server gets a “viewFile” or “downloadFile” request. You can see the series of request involved if you look at the RPC tab while running the upload sample.

I fix my Value Object. The codes is:

package model;

import java.io.OutputStream;

public class UploadFileVO {

	// public members
	public Integer pk;
	public String title;
	public OutputStream file;
	
	public OutputStream getFile() {
		return file;
	}
	public void setFile(OutputStream file) {
		this.file = file;
	}
	public Integer getPk() {
		return pk;
	}
	public void setPk(Integer pk) {
		this.pk = pk;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
}

I change my DMI, the code is:

    public DSResponse fetch(DSRequest dsRequest) throws Exception {
    	
        log.info("procesing DMI fetch operation");

    	DSResponse dsResponse = new DSResponse();

    	long startRow = dsRequest.getStartRow();
    	long endRow = dsRequest.getEndRow();
    	
    	long totalRows = 1;
    	       
        // clamp endRow to available rows and slice out requested range
        endRow = Math.min(endRow, totalRows);

    	List<UploadFileVO> results = new ArrayList<UploadFileVO>();
    	
    	UploadFileVO uploadFileVO = new UploadFileVO();
    	
    	uploadFileVO.setPk(new Integer(0));
    	uploadFileVO.setTitle("Mi Archivo");
    	    	
    	OutputStream os = new FileOutputStream("D:\\apache-tomcat-5.5.20\\bin\\MyFile.png");
    	
    	uploadFileVO.setFile(os);
    	
    	results.add(uploadFileVO);

        // DataSource protocol: return matching item beans
        dsResponse.setData(results);
                
        // tell client what rows are being returned, and what's available
        dsResponse.setStartRow(startRow);
        dsResponse.setEndRow(endRow);
        dsResponse.setTotalRows(totalRows);
    	
    	return dsResponse;
    	
    }

In the apache tomcat console appears:

=== 2010-06-17 17:07:54,390 [or24] WARN  RequestContext - rpcRequest.execute() failed: 
java.lang.Exception: Attempt to execute RPC DMI Builtin 'getAvailableScriptEngines' DENIED by server.properties configuration.  To enable this method, add it to the list of methods under RPCManager.enabledBuiltinMethods in server.properties
	at com.isomorphic.rpc.RPCDMI.execute(RPCDMI.java:180)
	at com.isomorphic.rpc.RPCDMI.execute(RPCDMI.java:66)
	at com.isomorphic.rpc.RPCRequest.execute(RPCRequest.java:229)
	at com.isomorphic.servlet.IDACall.handleRPCRequest(IDACall.java:197)
	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:102)
	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:54)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
	at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:248)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
	at java.lang.Thread.run(Unknown Source)

In the firebug appears RPC Tab - Request Tab appear:

{
    actionURL:"http://localhost:8080/transporte/isomorphic/IDACall", 
    showPrompt:true, 
    prompt:"Finding records that match your criteria...", 
    transport:"xmlHttpRequest", 
    promptStyle:"dialog", 
    bypassCache:true, 
    data:{
        criteria:{
        }, 
        operationConfig:{
            dataSource:"uploadFile", 
            operationType:"fetch", 
            textMatchStyle:"exact"
        }, 
        startRow:0, 
        endRow:75, 
        componentId:"mediaTileGrid", 
        appID:"builtinApplication", 
        operation:"uploadFile_fetch", 
        oldValues:{
        }
    }
}

In the firebug appears RPC Tab - Response Tab appear:

[
    {
        invalidateCache:false,
        endRow:1,
        data:[
            {
                file:{
                    FD:{},
                    channel:{open:true}
                },
                pk:0,
                title:"Mi Archivo"
            }
        ],
        status:0,
        totalRows:1,
        startRow:0,
        isDSResponse:true
    }
]

In the firebug console appears:

//isc_RPCResponseStart-->[
    {data:"Attempt to execute RPC DMI Builtin 'getAvailableScriptEngines' DENIED by server.properties configuration.  To enable this method, add it to the list of methods under RPCManager.enabledBuiltinMethods in server.properties",
     status:-1}
]//isc_RPCResponseEnd

Once again, do not send the file back as part of a response to a “fetch” operation, only in response to “viewFile” or “downloadFile”. Watch what the sample is doing and copy it.

The example does not run.

When I try to upload a file, the example freeze and appear a popup with “Saving Form”, later appear another popup with “Time out”.

I don´t have this sample code locally (SmartClient_70rc2_Evaluation).

Please tell me what to do.

There’s a website-specific issue affecting that example related to “sand boxing” the sample so that you only see your own uploads. You can copy the code locally and run it.