p:graphicImage is not working inside h:dataTable/p:dataTable
If I may add my contribution for this case but *in a portlet environment*.undermensch wrote: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:
GraphicImageRendererPrimeResourceHandlerCode: 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 { ...
Good Luck!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]; ...
I am using Liferay 6.0 and this approach works, but you have to use the following code in your custom ResourceHandler ::
Code: Select all
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;
ResourceResponse response = (ResourceResponse) context.getExternalContext().getResponse();
response.setContentType(content.getContentType());
byte[] buffer = new byte[2048];
int length;
while ((length = (content.getStream().read(buffer))) >= 0) {
response.getPortletOutputStream().write(buffer, 0, length);
}
// response.setStatus(200); // I'm not sure how to set this.
response.getPortletOutputStream().flush();
context.responseComplete();
} catch(Exception e) {
logger("Error in streaming dynamic resource.");
} finally {
session.remove(dynamicContentId);
}
-
- Posts: 40
- Joined: 31 Aug 2011, 05:25
I am experiencing the same issues with dynamic images and the datatable. What is the exact solution discussed here? Are we saying that the source files get modified with those two methods and that the entire primefaces library should be compiled with the changes and added to our project? Or am I missing something here and there is an easier way of fixing this issue?
-
- Posts: 4
- Joined: 29 Jan 2012, 18:21
me too - still having problems like:
- Usage of f:attribute breaks stream resource (requesting UI root context inside java Bean kills stream)
- Usage of f:param fails, because the parameter is not availible request, where the paramMap is completly empty - this results in exception
Displaying single Images is possible, but it would be nice, if f:param will work again like described in UserManual 3.0!
Thank you!
- Usage of f:attribute breaks stream resource (requesting UI root context inside java Bean kills stream)
- Usage of f:param fails, because the parameter is not availible request, where the paramMap is completly empty - this results in exception
Displaying single Images is possible, but it would be nice, if f:param will work again like described in UserManual 3.0!
Thank you!
Roo 1.2.0.RELEASE
Spring 3
PrimeFaces 3.0.1
Spring 3
PrimeFaces 3.0.1
-
- Posts: 48
- Joined: 28 Feb 2012, 11:22
Hi,
Thanks
Jonny
I'm experiencing the same thing. Drives me crazy!!!> Usage of f:param fails, because the parameter is not availible request, where the paramMap is completly empty
Thanks
Jonny
Primefaces 3.3 | Mojarra 2.1.8 | Weld 1.1.8.Final | Tomcat 6.0.29
-
- Posts: 3
- Joined: 09 Feb 2012, 13:32
Should this example work with PrimeFaces-3.3 also?mvodas wrote:I managed to solve it. Dimitar your help was key to solving it, thank you again. So here is all of my code in case someone else encounters the same problem...
I tried to include this small example into my project, but if I use @SessionScoped annotation for the SBean then I get the following Exception:
Code: Select all
SEVERE: Error Rendering View[/pages/diagnostics/index.xhtml]
java.lang.IllegalStateException: PWC3999: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2885)
at org.apache.catalina.connector.Request.getSession(Request.java:2582)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:920)
at com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:155)
at com.sun.faces.mgbean.BeanManager$ScopeManager$SessionScopeHandler.handle(BeanManager.java:575)
at com.sun.faces.mgbean.BeanManager$ScopeManager.pushToScope(BeanManager.java:458)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:410)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:103)
at com.sun.el.parser.AstValue.getValue(AstValue.java:179)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at com.sun.faces.facelets.component.UIRepeat.getValue(UIRepeat.java:273)
at com.sun.faces.facelets.component.UIRepeat.getDataModel(UIRepeat.java:249)
at com.sun.faces.facelets.component.UIRepeat.setIndex(UIRepeat.java:443)
at com.sun.faces.facelets.component.UIRepeat.doVisitChildren(UIRepeat.java:673)
at com.sun.faces.facelets.component.UIRepeat.visitTree(UIRepeat.java:631)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIForm.visitTree(UIForm.java:344)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1601)
at com.sun.faces.application.view.StateManagementStrategyImpl.saveView(StateManagementStrategyImpl.java:160)
at com.sun.faces.application.StateManagerImpl.saveView(StateManagerImpl.java:133)
at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:419)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Sorry for the question, I don't understand some basics of JSF I think..
I've also had a hard time making this working: now it is mostly working as follows:
- if imgid is null, just put the placeholder, which will generate the correct url for latter image downloading
- most of the code came from http://stackoverflow.com/questions/8304 ... pdatatable
public StreamedContent getImageById() {
FacesContext context = FacesContext.getCurrentInstance();
String id = context.getExternalContext().getRequestParameterMap().get("imgid");
if (StringUtils.isBlank(id)) {
logger.warn("Placing the placeholder for image now");
return new DefaultStreamedContent();
}
Long imgId = new Long(id);
Image img = imageService.retrieve(imgId);
logger.debug("Returning image for image id {} - Image is {}", imgId, img.getName());
return new DefaultStreamedContent(new ByteArrayInputStream(img.getImage()), img.getMimeType(),
img.getName());
}
the jsf file is:
<p:graphicImage id="serviceImgRef"
value="#{imageDisplayController.imageById}"
title="#{serviceImg.name}"
alt="#{serviceImg.description}" cache="false" width="100px" height="100px">
<f:param
name="imgid"
value="#{serviceImg.id}" />
</p:graphicImage>
- if imgid is null, just put the placeholder, which will generate the correct url for latter image downloading
- most of the code came from http://stackoverflow.com/questions/8304 ... pdatatable
public StreamedContent getImageById() {
FacesContext context = FacesContext.getCurrentInstance();
String id = context.getExternalContext().getRequestParameterMap().get("imgid");
if (StringUtils.isBlank(id)) {
logger.warn("Placing the placeholder for image now");
return new DefaultStreamedContent();
}
Long imgId = new Long(id);
Image img = imageService.retrieve(imgId);
logger.debug("Returning image for image id {} - Image is {}", imgId, img.getName());
return new DefaultStreamedContent(new ByteArrayInputStream(img.getImage()), img.getMimeType(),
img.getName());
}
the jsf file is:
<p:graphicImage id="serviceImgRef"
value="#{imageDisplayController.imageById}"
title="#{serviceImg.name}"
alt="#{serviceImg.description}" cache="false" width="100px" height="100px">
<f:param
name="imgid"
value="#{serviceImg.id}" />
</p:graphicImage>
---------------------
Primefaces 4.0
JSF 2.2.2 (mojarra)
tomcat 7.0.29
Primefaces 4.0
JSF 2.2.2 (mojarra)
tomcat 7.0.29
-
- Information
-
Who is online
Users browsing this forum: No registered users and 30 guests