Return-Path: X-Original-To: apmail-myfaces-users-archive@www.apache.org Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1D51711F0F for ; Mon, 13 May 2013 17:52:11 +0000 (UTC) Received: (qmail 25905 invoked by uid 500); 13 May 2013 12:25:30 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 25600 invoked by uid 500); 13 May 2013 12:25:30 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 25570 invoked by uid 99); 13 May 2013 12:25:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 May 2013 12:25:29 +0000 X-ASF-Spam-Status: No, hits=2.6 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS,T_FRT_BELOW2,URIBL_GREY X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of christian.beikov@gmail.com designates 209.85.220.169 as permitted sender) Received: from [209.85.220.169] (HELO mail-vc0-f169.google.com) (209.85.220.169) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 13 May 2013 12:25:25 +0000 Received: by mail-vc0-f169.google.com with SMTP id kw10so1742853vcb.28 for ; Mon, 13 May 2013 05:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=n7/IqpwoOt3exe4xTg9uTRxqBCiOHsfzVj6X+VWkJJ4=; b=ovaWDFXgDCAEoFG53Nqhbbkhh85k/D4fOCGPj0DNmPVswepUGUOeADJ555tZ/FshNq sPjxN5sIpSdPhgfAtz/DA2WIQiM+OyDGqY96O8UoWM5EuZ3IABH8FTDprFP4uUPJtlbJ 9amlnxyQ2wl6hmVmcxk84AU4XIA0pxjq3deysSy89OoM9JuHz8Z1R3Da9c8WaCFs6kJh F5HuwNUEJmZbxlx5NkkSXWvCRQubFJmvmy84Bi33CJ+ubVTbaXtHnwzIh3HPftpVIfnf OtwfxwiR7zZNk72nJwJXgbMc3vCbeucnaT/B7L0Q9OqjLwrrPB97UJLN4x3B0D/iBe4T EvGg== MIME-Version: 1.0 X-Received: by 10.220.189.9 with SMTP id dc9mr18061079vcb.8.1368447904694; Mon, 13 May 2013 05:25:04 -0700 (PDT) Received: by 10.220.28.70 with HTTP; Mon, 13 May 2013 05:25:04 -0700 (PDT) In-Reply-To: References: Date: Mon, 13 May 2013 14:25:04 +0200 Message-ID: Subject: Re: Unwrap CC ValueExpression? From: Christian Beikov To: MyFaces Discussion Content-Type: multipart/alternative; boundary=001a11c1c63a40ce9004dc989b88 X-Virus-Checked: Checked by ClamAV on apache.org --001a11c1c63a40ce9004dc989b88 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I'd rather say this should be fixed by restoring the view before accessing the expression. I have done something like that for DynamicContentResourceHandler which probably is used in this case here too. Basically you need to save the viewId and the expression together in the session so you are able to restore the adequate expression in the resource handler. I did the following for GraphicImageRenderer: @Override protected String getImageSrc(FacesContext context, GraphicImage image) = { String src =3D null; String name =3D image.getName(); if(name !=3D null) { String libName =3D image.getLibrary(); ResourceHandler handler =3D context.getApplication().getResourceHandler(); Resource res =3D handler.createResource(name, libName); if(res =3D=3D null) { return "RES_NOT_FOUND"; } else { return context.getExternalContext().encodeResourceURL(res.getRequestPath()); } } else { Object value =3D image.getValue(); if (value =3D=3D null) { return ""; } else if(value instanceof String) { src =3D getResourceURL(context, (String) value); } else if (value instanceof StreamedContent) { ViewHandler viewHandler =3D context.getApplication().getViewHandler(); StreamedContent streamedContent =3D (StreamedContent) value= ; Resource resource =3D context.getApplication().getResourceHandler().createResource("dynamicconten= t", "primefaces", streamedContent.getContentType()); String resourcePath =3D resource.getRequestPath(); // servlet path/prefix is added already in ViewHandler.getActionURL so remove it here resourcePath =3D resourcePath.substring(resourcePath.indexOf("/javax.faces.resource/")); resourcePath =3D viewHandler.getActionURL(context, resourcePath); String rid =3D createUniqueContentId(context); StringBuilder builder =3D new StringBuilder(resourcePath); if(resourcePath.contains("?")) builder.append("&"); else builder.append("?"); builder.append(DynamicContentResourceHandler.DYNAMIC_CONTENT_PARAM).append(= "=3D").append(rid); builder.append("&").append("ln=3Dprimefaces"); for (UIComponent kid : image.getChildren()) { if (kid instanceof UIParameter) { UIParameter param =3D (UIParameter) kid; builder.append("&").append(param.getName()).append("=3D").append(param.getV= alue()); } } src =3D builder.toString(); Map dynamicContentMap =3D new HashMap(); dynamicContentMap.put(DynamicContentResourceHandler.DYNAMIC_CONTENT_VALUE_E= XPRESSION_KEY, image.getValueExpression("value").getExpressionString()); dynamicContentMap.put(DynamicContentResourceHandler.DYNAMIC_CONTENT_VIEW_ID= _KEY, context.getViewRoot().getViewId()); context.getExternalContext().getSessionMap().put(rid, dynamicContentMap); } // Add caching if needed if (!image.isCache()) { src +=3D src.contains("?") ? "&" : "?"; src =3D src + "primefaces_image=3D" + UUID.randomUUID().toString(); } } return src; } And then I have the DynamicContentResourceHandler: public class DynamicContentResourceHandler extends PrimeResourceHandler{ private final static Logger logger =3D Logger.getLogger(DynamicContentResourceHandler.class.getName()); public static final String DYNAMIC_CONTENT_VIEW_ID_KEY =3D "viewId"; public static final String DYNAMIC_CONTENT_VALUE_EXPRESSION_KEY =3D "valueExpression"; public static final String DYNAMIC_CONTENT_PARAM =3D "pfdrid"; public DynamicContentResourceHandler(ResourceHandler wrapped) { super(wrapped); } @Override public void handleResourceRequest(FacesContext context) throws IOException { Map params =3D context.getExternalContext().getRequestParameterMap(); String library =3D params.get("ln"); String dynamicContentId =3D params.get(DYNAMIC_CONTENT_PARAM); if(dynamicContentId !=3D null && library !=3D null && library.equals("primefaces")) { Map session =3D context.getExternalContext().getSessionMap(); StreamedContent content =3D null; try { @SuppressWarnings("unchecked") Map dynamicContentMap =3D (Map) session.get(dynamicContentId); if(dynamicContentMap !=3D null){ String viewId =3D dynamicContentMap.get(DYNAMIC_CONTENT_VIEW_ID_KEY); String dynamicContentEL =3D dynamicContentMap.get(DYNAMIC_CONTENT_VALUE_EXPRESSION_KEY); // Workaround for view based scopes context.setViewRoot(context.getApplication().getViewHandler().createView(co= ntext, viewId)); ELContext eLContext =3D context.getELContext(); ValueExpression ve =3D context.getApplication().getExpressionFactory().createValueExpression(conte= xt.getELContext(), dynamicContentEL, StreamedContent.class); content =3D (StreamedContent) ve.getValue(eLContext); ExternalContext externalContext =3D context.getExternalContext(); externalContext.setResponseStatus(HttpServletResponse.SC_OK); externalContext.setResponseContentType(content.getContentType()); byte[] buffer =3D new byte[2048]; int length; InputStream inputStream =3D content.getStream(); while ((length =3D (inputStream.read(buffer))) >=3D 0) = { externalContext.getResponseOutputStream().write(buffer, 0, length); } externalContext.getResponseOutputStream().flush(); context.responseComplete(); } else { ExternalContext externalContext =3D context.getExternalContext(); externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND); externalContext.getResponseOutputStream().flush(); context.responseComplete(); } } catch(Exception e) { logger.log(Level.SEVERE, "Error in streaming dynamic resource.", e); } finally { session.remove(dynamicContentId); if(content !=3D null) { content.getStream().close(); } } } else { super.handleResourceRequest(context); } } } This at least works for me, hope it can help you too. 2013/5/13 Thomas Andraschko > Hi Kito, > > CC: > > -------------------------------------------------------------------------= --------------------------------------- > > type=3D"org.primefaces.model.StreamedContent" required=3D"true" /> > > > > player=3D"pdf"/> > > > -------------------------------------------------------------------------= --------------------------------------- > > View: > > -------------------------------------------------------------------------= --------------------------------------- > > > -------------------------------------------------------------------------= --------------------------------------- > > PF receives the Expression String via: > > -------------------------------------------------------------------------= --------------------------------------- > media.getValueExpression("value").getExpressionString(); > > -------------------------------------------------------------------------= --------------------------------------- > > If it should work inside a CC, we must receive "#{cc.attrs.pdfStream}" > instead of "#{cc.attrs.pdfStream}". > > How can get the real expression here? > > Thanks, > Thomas > > > 2013/5/13 Kito Mann > > > Hello Thomas, > > > > I think this is doable. Can you send us your composite component code? > > > > ___ > > > > Kito D. Mann | @kito99 | Author, JSF in Action > > Virtua, Inc. | http://www.virtua.com | JSF/Java EE training and > consulting > > http://www.JSFCentral.com - JavaServer Faces FAQ, news, and info | > > @jsfcentral > > +1 203-998-0403 > > > > * JSF2 in Action Course - 6/17 - London: > > http://skillsmatter.com/course/home/jsf-and-ajax/ng-6708 > > * Listen to the Enterprise Java Newscast: * > > http://blogs.jsfcentral.com/JSFNewscast/ > > * > > * JSFCentral Interviews Podcast: > > http://www.jsfcentral.com/resources/jsfcentralpodcasts/ > > * Sign up for the JSFCentral Newsletter: > > http://oi.vresp.com/?fid=3Dac048d0e17 > > > > > > On Mon, May 13, 2013 at 7:17 AM, Thomas Andraschko < > > andraschko.thomas@gmail.com> wrote: > > > > > Hi, > > > > > > is it possible unwrap a CC ValueExpresion? > > > i found a bug with PrimeFaces p:media inside a composite component an= d > i > > > would like to fix it. > > > > > > If you pass the EL via a CC attr (e.g. #{myController.content}) and > > attach > > > it to p:media (e.g. #{cc.attrs.content}), > > > p:media gets the ValueExpression and saves them in the session, to > later > > > stream the content in a resource request. > > > Later the ResourceHandler evaluates it and tries to get the value of > > > #{cc.attrs.content}, which can't work ofc. > > > > > > So is it possible to extract the "real" EL before store it in the > > session? > > > Is there a solution which also works in mojarra? > > > > > > > > > Regards, > > > Thomas > > > > > > --=20

Mit freundlichen Gr=FC=DFen,

Christian Beikov
Blazebit Design & Developing
http://www.blazebit.com
--001a11c1c63a40ce9004dc989b88--