p:graphicImage is not working inside h:dataTable/p:dataTable
-
- Posts: 65
- Joined: 27 Feb 2011, 18:04
I keep on trying to solve this... Please, take a look to my code, because it is pretty similiar to others' working in this topic. Maybe there's a problem because a container? The image is to be displayed within a tab
----------------------------------------------------------------------------
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
- undermensch
- Posts: 140
- Joined: 08 Jul 2010, 14:37
- Location: Florida, United States
What is the scope of your backing bean?
PrimeFaces-11.0.6 / Wildfly 24
-
- Posts: 65
- Joined: 27 Feb 2011, 18:04
undermensch,
it's view scoped, but I have also tried sessionscoped, without success.
it's view scoped, but I have also tried sessionscoped, without success.
----------------------------------------------------------------------------
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
- undermensch
- Posts: 140
- Joined: 08 Jul 2010, 14:37
- Location: Florida, United States
I have gotten this to work, both in a datatable and in a dynamically updated panel with two modifications, 1 to the graphicimage renderer, the other to the PrimeResourceHandler. I don't intend to use these changes long term, but until I have more time, I'm using them. Here they are:
GraphicImageRenderer
PrimeResourceHandler
Good Luck!
GraphicImageRenderer
Code: Select all
...
protected String getImageSrc(FacesContext context, GraphicImage image) {
String src = null;
Object value = image.getValue();
if(value == null) {
src = "";
}
else {
if(value instanceof StreamedContent) {
StreamedContent streamedContent = (StreamedContent) value;
Resource resource = context.getApplication().getResourceHandler().createResource("dynamiccontent", "primefaces", streamedContent.getContentType());
String resourcePath = resource.getRequestPath();
String rid = createUniqueContentId(context);
StringBuilder builder = new StringBuilder(resourcePath);
builder.append("&").append(PrimeResourceHandler.DYNAMIC_CONTENT_PARAM).append("=").append(rid);
for(UIComponent kid : image.getChildren()) {
if(kid instanceof UIParameter) {
UIParameter param = (UIParameter) kid;
builder.append("&").append(param.getName()).append("=").append(param.getValue());
}
}
src = builder.toString();
context.getExternalContext().getSessionMap().put(rid, value);
//context.getExternalContext().getSessionMap().put(rid, image.getValueExpression("value").getExpressionString());
}
else { ...
Code: Select all
...
public void handleResourceRequest(FacesContext context) throws IOException {
Map<String, String> params = context.getExternalContext().getRequestParameterMap();
String library = params.get("ln");
String dynamicContentId = params.get(DYNAMIC_CONTENT_PARAM);
//logger.log(Level.INFO, "library set to: " + library);
if (dynamicContentId != null && library != null && library.equals("primefaces")) {
Map<String, Object> session = context.getExternalContext().getSessionMap();
try {
Object dynamicContentEL = (Object) session.get(dynamicContentId);
//String dynamicContentEL = (String) session.get(dynamicContentId);
//ELContext eLContext = context.getELContext();
//ValueExpression ve = context.getApplication().getExpressionFactory().createValueExpression(context.getELContext(), dynamicContentEL, StreamedContent.class);
//StreamedContent content = (StreamedContent) ve.getValue(eLContext);
StreamedContent content = (StreamedContent) dynamicContentEL;
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
response.setContentType(content.getContentType());
byte[] buffer = new byte[2048];
...
PrimeFaces-11.0.6 / Wildfly 24
-
- Posts: 65
- Joined: 27 Feb 2011, 18:04
Uf, I will try... but this is rather tricky for me (a newbie with PF, and also JSF). May I then consider there's a bug with graphicImage as a Streamedcontent?
----------------------------------------------------------------------------
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
-
- Posts: 8
- Joined: 12 Aug 2011, 16:15
Hello everyone,
Are there any news for the ccastro333's case ?
I am trying to send a param to backing bean from graphicImage, but it always returns null:
<p:dataTable value="#{myBean.items}" var="item">
<p:graphicImage value="#{myBean.streamedContent}">
<f:param name="param_name" value="item.itemId"/>
</p:graphicImage>
</p:dataTable>
---------
when trying to retrieve it through:
String image_id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param_name");
It always evaluates to null.
Any help?
Are there any news for the ccastro333's case ?
I am trying to send a param to backing bean from graphicImage, but it always returns null:
<p:dataTable value="#{myBean.items}" var="item">
<p:graphicImage value="#{myBean.streamedContent}">
<f:param name="param_name" value="item.itemId"/>
</p:graphicImage>
</p:dataTable>
---------
when trying to retrieve it through:
String image_id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("param_name");
It always evaluates to null.
Any help?
Eclipse Kepler, WAS 8.5.5, Java EE 6, PrimeFaces 4.0, Mojarra 2.2.5 (JSF 2.2)
-
- Posts: 65
- Joined: 27 Feb 2011, 18:04
Hi,
I used a workaround. I didn't use param, but attribute. The only problem with that is you have to harcode the name of the component in getStreamedImage method. I think the natural way of doing this is with param, but...
xhtml (within a dataGrid)
Bean
IitemImages is a List containing ItemImageView, a wrapper for the actual image.
And, for the second part of my case, I managed to get the images rendered only by applying the "tunning" suggested a couple posts above. Another workarround that I don't like, and I suspect I am getting collateral error while PF has to find client Ids in certain situations. But images render.
I used a workaround. I didn't use param, but attribute. The only problem with that is you have to harcode the name of the component in getStreamedImage method. I think the natural way of doing this is with param, but...
xhtml (within a dataGrid)
Code: Select all
<p:graphicImage id="itemImgComp" value="#{itemsBean.streamedImage}" rendered="#{not empty item.defaultImage}">
<f:attribute name="item_id" value="#{item.id}"/>
</p:graphicImage>
Code: Select all
public StreamedContent getStreamedImage() {
byte[] emptyImage = new byte[0];
StreamedContent streamedImage = null;
UIComponent component = FacesContext.getCurrentInstance().getViewRoot().findComponent("itemsForm:itemList:itemImgComp");
Map attributes = component.getAttributes();
Integer item_id = (Integer)attributes.get("item_id");
if(item_id != null && itemImages != null){
if(itemImages.get(item_id.toString()) != null){
streamedImage = new DefaultStreamedContent(
new ByteArrayInputStream(((ItemImageView)itemImages.get(item_id.toString())).getImage()), "image/jpg");
}
}else{
streamedImage = new DefaultStreamedContent(new ByteArrayInputStream(emptyImage), "image/jpg");
}
return streamedImage;
}
And, for the second part of my case, I managed to get the images rendered only by applying the "tunning" suggested a couple posts above. Another workarround that I don't like, and I suspect I am getting collateral error while PF has to find client Ids in certain situations. But images render.
----------------------------------------------------------------------------
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
-
- Posts: 65
- Joined: 27 Feb 2011, 18:04
Hi,
the methods are as undermesch said, and they are in
org\primefaces\application\PrimeResourceHandler.java
and
org\primefaces\component\graphicimage\GraphicImageRenderer.java
at least, in 3.0.M2
you can simply copy and paste the methods as they are in the post
the methods are as undermesch said, and they are in
org\primefaces\application\PrimeResourceHandler.java
and
org\primefaces\component\graphicimage\GraphicImageRenderer.java
at least, in 3.0.M2
you can simply copy and paste the methods as they are in the post
----------------------------------------------------------------------------
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
primefaces-3.4
mojarra-2.1.2-FCS
Tomcat 7
Thanks Castro .. I was using 3.01M .I got the files made all the changes does not work .. another unusual thing I saw that method<p:p:graphicImage called first 2 then 3 times for an array of two values .
Last edited by bhakav on 20 Aug 2011, 21:18, edited 1 time in total.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 44 guests