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