Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Equivalent to getValueIcon in SmartGWT

    I recently made the change to develop client side code in SmartGWT as opposed to JavaScript, and am having a little ;-) trouble with displaying images within a ListGrid.

    I have seen a couple of other related threads such as
    Code:
    http://forums.smartclient.com/showthread.php?t=9060&highlight=showfileinline
    and
    Code:
    http://forums.smartclient.com/showthread.php?t=9739&highlight=addEmbeddedComponent
    so I can see I'm not the first to encounter difficulties.

    The images I am displaying are actually stored in the database, but they are then persisted to the local file system on the server for retrieval by client side code.

    I succeeded in using the addEmbeddedComponent route but I don't really want to continue using this option for some behavioural reasons (the ListGrid doesn't get the start editing notification when the user double clicks on the image because the Img instance receives this notification.)

    I was really happy with the way getValueIcon works because I had a function looking like this:

    Code:
    getValueIcon:
    	function( field, value, record )
    	{
    		var result = this.Super( "getValueIcon", arguments );
    		if ( field.type == "binary" )
    		{
    			//  We need to use the appropriate image based on the table name and id number
    			var imageForRecord = Img.create
    			(
    				{
    					autoFit: true,
    					src: Page.getAppImgDir() + recordsGrid.dataSource.tableName + "/" + record.id,
    					autoDraw: false,
    					overflow: true
    				}
    			);
    			field.valueIconWidth = 100;
    			field.valueIconHeight = 70;
    			result = imageForRecord;
    		}
    		return result;
    	}
    There is no getValueIcon method on ListGrid although there is a method ListGridField.setValueIcons( Map<String, String> ), but I didn't succeed in using this because the key value in my case is binary data.

    I have tried ListGridField.setShowFileInline( true ) in conjunction with a datasource definition as follows but didn't get any luck.
    Code:
    <DataSource ID="images1276259338037ds" tableName="images" title="images" >
    	<fields>
    		<field name="id" type="sequence" hidden="false" primaryKey="true" canEdit="false"/>
    		<field name="description" type="text" hidden="false" primaryKey="false" length = "100" />
    		<field name="picture" type="imageFile" hidden="false" primaryKey="false" />
    	</fields>
    </DataSource>
    Anyway, I'm really happy to be developing all aspects of the solution in Java within Eclipse because I can debug my server- and client-side code without switching to any other environment and of course I can see all the methods and hierarchy tree for components immediately. Fantastic!

    Do you have any suggestions please as to which route I should take?

    #2
    Hi Isomorphic,

    I discovered that when showFileInline is specified for the appropriate ListGridField, this results in a DSRequest being sent to the IDACall servlet whose operation type is 'viewFile'. So following on from the suggestion you made in this thread

    Code:
    http://forums.smartclient.com/showthread.php?t=9060&highlight=showfileinline
    with your response

    Originally posted by Isomorphic
    To provide the file for viewing or downloading, return an InputStream under the name of the binary field in the data you provide to DSResponse.setData().
    Code:
    public DSResponse handleDSRequest( final DSRequest dsRequest, final RPCManager rpcManager, final RequestContext reqContext ) throws Exception
    {
    	if ( operationType.equalsIgnoreCase( "viewFile" ) )
    	{
    		final byte[] byteStream = [a reference to the full byte stream for the image];
    		final ByteArrayInputStream stream = new ByteArrayInputStream( byteStream );
    		final Map mapReturn = new HashMap();
    		mapReturn.put( dsRequest.getDownloadFieldName(), stream );
    		response.setData( mapReturn );
    		response.setStatus( DSResponse.STATUS_SUCCESS );
    Can you tell me if I'm on the right lines, or whether there is anything obviously wrong?

    Thanks

    Alastair

    Comment

    Working...
    X