0

I was able to save an image as blob type in MySQL and now I want to display it using the struts2 jquery grid widget. I used the edittype="image" but it didn't work. It only displays some string. Any suggestion on which edittype i should use?

here is my jquery grid:

 <sjg:grid
        id="testresulttable1"
        caption="Test Result Summary"
        dataType="json"
        href="%{testtrsurl}"
        pager="true"
        gridModel="gridTRSModel"
        rowList="10,15,20"
        rowNum="15"
        viewrecords="true"
        viewsortcols="[true, 'horizontal', true]"
        resizable="true"
        multiselect="false"
        loadonce="false"
    >
<sjg:gridColumn
   name="screenshot"
   index="screenshot"
   title="screenshot"
   sortable="true"
   edittype="image"
/>

</sjg:grid>

thanks in advance for your help.

2

2 Answers 2

1

Actually you cannot display blob-type in grid directly, what you can do is some work-arounds. Have image-id as hidden fields in grid, have a formatter which calls an function, which will read the image-id and get the blob data thru ajax call.

Then you can assign it to <img> in some <iframe> by setting its src attribute to binaryData recieved by ajax call.. Let me know once you implement it.

I had implemented similar logic for showing xml file which is read from mysql database as blob.

Note:Don't use blob directly, convert it to byte-array before you assign it to outputstream/inputstream :)

Sign up to request clarification or add additional context in comments.

1 Comment

hi DarkHorse... can you share the logic you made for displaying xml from mysql database? I will see if i can use the same logic for displaying images. thanks in advance
1

i took in the answers provided by Quaternion and Darkhorse and implemented them (thanks for your inputs). I also got a help from another blog.

Here is the solution: a. instead of blob, I used varchar and just store the filepath of the image b. in my grid, i used formatter which is pointing to a javascript c. the javascript is calling an action which returns a customised result type which in turn is passed on to the grid that calls the javascript thru the formatter attribute.

here is the javascript:

function formatImage(cellvalue, options, row) {

    if(!cellvalue){
        return "n/a";
    }else{
        var action = "http://localhost:8181/MySel20Proj-1.0/imageAction.action?imageId=" + cellvalue;

        return "<a href="+"'"+action+"'"+"title='' class='thickbox'><img src='" + action + "'  width='30' height='30 align='middle' border='0'/></a>"; 

    }   
}

for the struts action/config, please refer to this site: http://www.mkyong.com/struts2/struts-2-dynamic-image-example/

2 Comments

Sorry, couldn't provide you with sample code, as it was part of project of my prev employer..and good u made one of your own :)
it's ok...tnx DarkHorse.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.