Search This Blog

Saturday, March 19, 2016

27. OAF Showing image from the database


3.1 in the VO add new column   "Null Image_Source" below created VO from EO.
SELECT StirlingPatientEntryEO.PATIENT_ID,
       StirlingPatientEntryEO.PATIENT_NAME,
       StirlingPatientEntryEO.REVIEW,
       StirlingPatientEntryEO.PHONE_NUMBER,
       StirlingPatientEntryEO.SEX,
       StirlingPatientEntryEO.AGE,
       StirlingPatientEntryEO.AMOUNT,
       StirlingPatientEntryEO.DATE_CHECKED,
       StirlingPatientEntryEO.ADDRESS,
       StirlingPatientEntryEO.LAST_UPDATE_DATE,
       StirlingPatientEntryEO.LAST_UPDATED_BY,
       StirlingPatientEntryEO.CREATION_DATE,
       StirlingPatientEntryEO.CREATED_BY,
       StirlingPatientEntryEO.LAST_UPDATE_LOGIN,
       StirlingPatientEntryEO.IMAGE,
       Null Image_Source
FROM XXSTIRLING_PATIENT_ENTRY_TABLE StirlingPatientEntryEO
3.2 Created UpdatePG with the above created VO
Check how to create UpdatePG in OAF in this Blog
3.3 for the Attribute StirlingPatientEntryEO.IMAGE below are the properties.
ID imageIT
style image
datatype CLOB
ViewInstance PatientEntryVO1
ViewAtribute Image
3.4 Add code under the processRequest of UpdagePG Controller.
           //for image display starts here
                     if(pageContext.isLoggingEnabled(1))
                     pageContext.writeDiagnostics(this, "Entering processRequest..", 1);
                     Serializable[] param = {pageContext.getTemporaryImageLocation()};
                     pageContext.getApplicationModule(webBean).invokeMethod("initImg",param); //initImg is the method we will create in AM
                     OAImageBean oaimagebean = (OAImageBean)webBean.findIndexedChildRecursive("imageIT"); //id of image in the PG
                     if(oaimagebean != null)
                     {
                     oaimagebean.setAttributeValue(UIConstants.SOURCE_ATTR, new OADataBoundValueViewObject(oaimagebean, "ImageSource")); //ImageSource we created null column in the VO
                     oaimagebean.setWidth(100);
                     oaimagebean.setHeight(110);
                     oaimagebean.setBorderWidth(2);
                     }
                     if(pageContext.isLoggingEnabled(1))
                     pageContext.writeDiagnostics(this, "Leaving processRequest..", 1);
                     }
               //for image display ends here here
              
              

3.5 method in AM .
//for image dob starts here
public void initImg(String s2)
{
OAViewObjectImpl oaviewobjectimpl = getPatientEntryVO1();      //VO name
oaviewobjectimpl.executeQuery();
if(oaviewobjectimpl.first() != null)
{
OARow oarow = (OARow)oaviewobjectimpl.first();
BlobDomain blobdomain = (BlobDomain)oarow.getAttribute("Image"); //attribute name of blob column i.e., Image
if(blobdomain != null)
{
String s3 = createFile(s2, blobdomain, (String)oarow.getAttribute("PatientName")); //attribute name of PatientName
oarow.setAttribute("ImageSource", s3);
}
}
}
public void fromInputToOutput(InputStream inputstream, OutputStream outputstream)
throws IOException
{
byte abyte0[] = new byte[255];
for(int i = 255; i == 255;)
{
i = inputstream.read(abyte0);
if(i < 0)
break;
outputstream.write(abyte0, 0, i);
}
outputstream.close();
inputstream.close();
}
public String createFile(String s, BlobDomain blobdomain, String s1)
{
File file = new File(s);
if(!file.exists())
file.mkdirs();
File file1 = new File(s, s1);
try
{
fromInputToOutput(blobdomain.getBinaryStream(), new FileOutputStream(file1));
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
}
return "fwk/t/" + file1.getName();
}

//for image dob ends here              

ref: https://community.oracle.com/message/2197822#2197822

1 comment:

  1. Hi,

    I have implemented as suggested above.
    But, I'm getting the error "No method with signature - No method with signature - initImg(class java.lang.String)" in updatePG.
    Could you please help me with this?


    Regards
    Chandan

    ReplyDelete