• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

render myimage from backing bean method

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I deal with JSF with ADF BC as my model layer and i work on Jdeveloper 10.1.3.2

My Requirement:

My initial task was to display my blob image on my jsf. I did this by calling a method in my backing bean displayImage() which has the following code
ccdphotoAMImpl ccdam = (ccdphotoAMImpl) ADFUtils.getApplicationModule("ccdphotoAM");
ViewObjectImpl vo = ccdam.getvwCcdPhoto1();
//get my viewobject set the parameters for the query and execute
vo.setNamedWhereClauseParam("partyRefNo", partyRef);
vo.executeQuery();
if(vo.first()!= null){
System.out.println("vo.first() ");
BlobDomain imageFile = (BlobDomain) vo.getCurrentRow().getAttribute("ImageData");
FileOperations.displayFile(imageFile);
}
FileOperations.displayFile(imageFile) is another helper class that has a method which acts like the servlet doGet method.

Now what happens is my image gets loaded in a new page which has the following url.

http://ip-address: /ccdphoto-ViewController-context-root/faces/displayPhoto.jspx;jsessionid=c0a8663d231da3d659987d034f81b899d8633fb2e6a2
which is similar to my initial page.
http://ip-address: /ccdphoto-ViewController-context-root/faces/displayPhoto.jspx

I want my image to be displayed in the original page in an image component
<!--h:graphicImage url="xyz" value = ""/-->

But i don't know how to call my backing bean method in this url.

Please help....
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't do it that way. Rather write an independent servlet which takes some parameters (partyRef?) and writes the desired image to the outputstream of the response based on the parameters.
 
Susan Monz
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for responding. Thats what they have tried here before when they used JSP+Struts+ ADFBC. Now we are using JSF, for which I was hoping there would be a way where i could avoid the servlet and call it through my backing bean. I was successful in getting my image but isn't there a way i can get my displayFile() method to redirect the image to my desired jsp. Perhaps somehow i could mention it in my faces-config.
HttpServletResponse response = (HttpServletResponse) extContext.getResponse();


response.setContentLength((int) length.intValue());
response.setContentType(CONTENT_TYPE);
// response.setHeader("Pragma","no-cache");
// response.setHeader("Cache-Control","no-cache, post-check=0, pre-check=0");
//response.setHeader("Cache-Control","no-store" );
response.setDateHeader("Expires", 0);
try {
InputStream in = blobDomain.getBinaryStream();
OutputStream out = response.getOutputStream();

byte[] buf = new byte[1024];
int count;
while ((count = in.read(buf)) >= 0) {
out.write(buf, 0, count);
}

in.close();
out.flush();
out.close();
facesContext.responseComplete();

I am sorry if i am pressing it. I was just hoping JSF had a way to do it.

Sudha
 
Susan Monz
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing, my collegue suggested I can return the response to a field in the backing bean and perhaps typecast it to a field in the bean.

Is this possible!
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's go in detail:

The h:graphicImage renders nothing else than a simple HTML <img> element. The value attribute of the h:graphicImage renders nothing else than the 'src' attribute of the <img> element. The HTML specification states that the 'src' attribute should point to a valid URL resource.

JSF can't do any magic to let it accept a binary stream, so that you could let the getter of the h:graphicImage value return a byte[] or so. You can also not let JSF create two response streams automagically, one for the page and another for the image. This makes all no sense.

You need to let it point to a valid URL resource somehow. The best and cleanest approach is to write a Servlet which does the desired task and call it in the h:graphicImage value.
 
Susan Monz
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right! Ok will do. Thanks for making it clear. What i have done is as you said written a servlet which i call in my image tag

<af: objectImage source = "/imageServlet?id=#{myBean.tempID}"
rendered = "false"
.......

have a text field to allow user to enter his employee id ( this case his id) and with ValueChangeListener = #{myBean.someaction}
populate this value into a field in myBean .Also I have a button in my jspx which on click will call a method in my backing bean will take this id and also set my objectImage1 rendered = "true"
So now my image get populated within the same page and when i want.

The reason i hesitated in using the servlet was coz i didn't know how to get the id which got populated in the very same page. Silly I know! But thank you.
 
Acetylsalicylic acid is aspirin. This could be handy too:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic