Dynamic Image and Ajax Request

UI Components for JSF
Post Reply
ufasoli
Posts: 42
Joined: 05 May 2010, 19:55

08 Nov 2010, 15:47

Hi I was wondering if it was possible to update a p:graphicImage with Ajax. I have a datatable with a list of users, when a row is selected a popup showing all the user info is updated then displayed.


my xhtml page

Code: Select all



<p:datatable selectionMode="single" onRowSelectUpdate="my-dialog" onComplete="myDialog.show()" selection="#{usersBean.selectedUser}" value="#{usersBean.users} " var="u">

.....
</p:datatable>


<p:dialog widgetVar="myDialog">

<p:outputPanel>

// User Info (Name, lastname, etc)

<p:graphicImage value="#{imgBean.userPhoto}"
</p:outputPanel>
</p:dialog>

my managed bean with all the users

Code: Select all


@ManagedBean
@ViewScoped
public class UsersBean{

   List<User> users;
   User selectedUser;
....


}

my image renderer managed bean :

Code: Select all


@ManagedBean
@RequestScoped
public class ImgBean{

@ManagedProperty(value="usersBean")
UsersBean usersBean;

 DefaultStreamedContent userPhoto;

@PostConstruct
public void init(){

     // getPhoto is a byte[]
    InputStream is  = new ByteArrayInputStream(newusersBean.getSelectedUser().getPhoto());
  
      userPhoto = new DefaultStreamedContent(is, , "image/jpeg")

  
   
}
}

I did a step by step execution and the user that is recovered in the postConstruct is the correct user, but I keep getting a server internal error 500 but with no error message. Is <p:graphicImage Ajax compatible ?


thank you in advance

Using :

Primefaces 2.2.RC1
JSF mojarra 2.0.3
Glassfish 3.1

fiktion
Posts: 100
Joined: 25 Aug 2010, 17:47

08 Nov 2010, 19:08

I had this same problem. I do not know if it is possible to get it to work with ajax but I got it working with an image servlet. This page helped me create a working servlet.

http://balusc.blogspot.com/2007/04/imageservlet.html

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

09 Nov 2010, 12:12

Hi,

I think, the problem is your ImgBean. It's request scoped (@RequestScoped). If you show dialog, the current request-response cycle is already done.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

ufasoli
Posts: 42
Joined: 05 May 2010, 19:55

15 Nov 2010, 21:48

Hi,
sorry for the late response, I finally managed to get it working with the servlet as fiktion suggested.

Thanks!!!

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 56 guests