Announcement

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

    Database blob files in a custom tilegrid

    SmartClient Version: v10.0p_2015-10-16/Pro Deployment (built 2015-10-16)

    I have a TileGrid similar to the one in http://www.smartclient.com/smartgwte...se/#upload_sql which shows user uploaded pictures from a database, but I want to use a custom TileConstructor like in http://www.smartclient.com/smartgwt/...#tiling_custom

    My problem is that I cant get the TileGrid to send viewFile requests when I use the custom TileConstructor.

    If I dont set a tile constructor everything works fine and the tilegrid viewFile requests.

    Am I wrong in using FileItem? Should I use something else in the tile constructor?

    TileGrid:
    Code:
    DataSource dataSource = DataSource.get("datasource");
    
    final TileGrid mediaTileGrid = new TileGrid();
    mediaTileGrid.setWidth("100%");  
    mediaTileGrid.setHeight(224);  
    mediaTileGrid.setTileWidth(100);  
    mediaTileGrid.setTileHeight(150);  
    mediaTileGrid.setDataSource(dataSource);  
    mediaTileGrid.setAutoFetchData(true);
    mediaTileGrid.setTileConstructor(AnimalTile.class.getName());
    TileConstructor class:
    Code:
    import com.smartgwt.client.types.Overflow;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.FileItem;
    import com.smartgwt.client.widgets.form.fields.StaticTextItem;
    
    public class AnimalTile extends DynamicForm {  
        
        public AnimalTile() {  
            setOverflow(Overflow.HIDDEN);  
            setHeight(150);  
            setWidth(200);  
      
            FileItem fileItem = new FileItem("image");
            fileItem.setType("imageFile");
            fileItem.setShowFileInline(true);
            fileItem.setRowSpan(3);  
            fileItem.setCanEdit(false);  
      
            StaticTextItem commonName = new StaticTextItem("title");  
            commonName.setShowTitle(false);  
            setFields(fileItem, commonName);  
        }  
    }
    ds.xml
    Code:
    <DataSource 
        ID="datasource" 
        serverConstructor="Servlet">
        <fields>  
            <field name="pk" type="sequence" hidden="true" primaryKey="true"/>  
            <field name="title"/>  
            <field name="image" type="imageFile"/>  
        </fields>  
    </DataSource>

    #2
    Did you enable Reflection? You don't seem to have, and it's required.

    You also haven't said what you're seeing, or whether there are any error messages or warnings.

    Comment


      #3
      Yes Reflection has been enabled in the same way as in http://www.smartclient.com/smartgwt/...#tiling_custom

      Code:
      public interface AnimalTileMetaFactory extends BeanFactory.MetaFactory {  
          BeanFactory<AnimalTile> getAnimalTileFactory();  
      }
      and then in the method where the TileGrid is instantiated I run
      Code:
      GWT.create(AnimalTileMetaFactory.class);
      I am not seeing any warnings or error messages.
      The tiles look like this: Click image for larger version

Name:	CustomTiles.PNG
Views:	113
Size:	1.8 KB
ID:	233220



      Here is the fetch response from the tilegrid datasource, remember this works when I am not using a custom TileConstructor.
      Code:
      {
          affectedRows:0,
          data:[
              {
                  image_filename:"file_1.jpg",
                  image_filesize:1024,
                  title:"title 1",
                  image_date_created:"2015-12-09T21:54:11.066",
                  pk:1
              },
              {
                  image_filename:"file_2.jpg",
                  image_filesize:1024,
                  title:"title 2",
                  image_date_created:"2015-12-09T21:54:11.066",
                  pk:2
              },
              {
                  image_filename:"file_3.jpg",
                  image_filesize:1024,
                  title:"title 3",
                  image_date_created:"2015-12-09T21:54:11.066",
                  pk:3
              }
          ],
          invalidateCache:false,
          isDSResponse:true,
          operationType:"fetch",
          queueStatus:0,
          status:0
      }

      Comment


        #4
        We think we see the problem - your custom tile consists of a DynamicForm, but that form has no DataSource, so it has no idea where to fetch files from.

        Comment


          #5
          Ahh yes, that solved it. Thanks a lot.

          Comment


            #6
            Just a quick follow up question.

            Is it possible to pass arguments to the TileConstructor?

            Comment


              #7
              No, unfortunately. Limitations of GWT make that impossible, or rather, the mechanism would be so awkward it would be far worse than any other way of providing initialization data you might come up with.

              Comment


                #8
                Alright, no problem. I figured out a way to do it without arguments.

                Thanks for the help.

                Comment

                Working...
                X