ICEfaces
  1. ICEfaces
  2. ICE-3606

The Download Resource example in the portlet version of Component Showcase uses servlet-specific APIs.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 1.7.2
    • Fix Version/s: 1.8DR#2
    • Component/s: Sample Apps
    • Labels:
      None
    • Environment:
      Component Showcase portlet
    • Assignee Priority:
      P2
    • Affects:
      Sample App./Tutorial

      Description

      Running the Download Resource example as a portlet causes this:
      22:42:06,442 ERROR [jsp:52] java.lang.ClassCastException: com.icesoft.faces.webapp.http.portlet.InterceptingPortletSession
      at org.icefaces.application.showcase.view.bean.examples.component.outputResource.OutputResourceBean.<init>(OutputResourceBean.java:59)
      at java.lang.Class.newInstance0(Class.java:350)
      at java.lang.Class.newInstance(Class.java:303)
      at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186)
      at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:106)
      at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:368)
      at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:230)
      at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:88)
      at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
      at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
      at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
      at org.apache.el.parser.AstValue.getValue(AstValue.java:103)
      at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
      at com.sun.faces.application.ValueBindingValueExpressionAdapter.getValue(ValueBindingValueExpressionAdapter.java:113)
      at com.icesoft.faces.component.outputresource.OutputResource.getResource(OutputResource.java:66)
      at com.icesoft.faces.component.outputresource.OutputResourceRenderer.encodeBegin(OutputResourceRenderer.java:24)
      at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)
      at com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer.encodeParentAndChildren(DomBasicRenderer.java:350)
      at com.icesoft.faces.renderkit.dom_html_basic.GridRenderer.encodeChildren(GridRenderer.java:203)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)

      The culprit is the constructor for the OutputResourceBean:

      public OutputResourceBean(){
      ServletContext context = ((HttpSession)FacesContext.getCurrentInstance().getExternalContext()
      .getSession(false)).getServletContext();
      try{
      imgResource = new ByteArrayResource( toByteArray( new FileInputStream( new File( context.getRealPath("/WEB-INF/resource/logo.jpg")))));
      pdfResource = new FileResource( new File(context.getRealPath("/WEB-INF/resource/WP_Security_Whitepaper.pdf")));
      pdfResourceDynFileName = new FileResource( new File(context.getRealPath("/WEB-INF/resource/WP_Security_Whitepaper.pdf")));
      }
      catch(Exception e){
      e.printStackTrace();
      }
      }

      It tries to create these resources based on real file locations using ServletContext.getRealPath(). Using the Servlet API directly in this way makes it unsuitable for working as a portlet. PortletContext has a matching API so that would be one option to fix it. A better solution would be to do the straight JSF thing and use one of the ExternalContext.getResource* methods (getResource, getResourceAsStream, or getResourcePaths) and avoid having to check for which environment it's running in.

      I'm commenting out this portlet for the 1.7.2 release and will mark it as being re-introduced into the 1.8 release.

        Activity

        Hide
        Philip Breau added a comment -

        This was fixed in rev 17720 - Oct 6, 2008, trunk and 1.7 branch are identical and do not reference servlet api

        Show
        Philip Breau added a comment - This was fixed in rev 17720 - Oct 6, 2008, trunk and 1.7 branch are identical and do not reference servlet api
        Hide
        Deryk Sinotte added a comment -

        I've checked the component in the trunk and the example seems to work fine there. There is an issue with the image attribute not providing the correct resource URL for portlets. I've created a new JIRA for that (http://jira.icefaces.org/browse/ICE-3670).

        Assigning back to Philip to commit changes to 1.7 branch.

        Show
        Deryk Sinotte added a comment - I've checked the component in the trunk and the example seems to work fine there. There is an issue with the image attribute not providing the correct resource URL for portlets. I've created a new JIRA for that ( http://jira.icefaces.org/browse/ICE-3670 ). Assigning back to Philip to commit changes to 1.7 branch.
        Hide
        Philip Breau added a comment -

        I think the sample in the head actually uses the proper non-context-specifc method for creating an output stream from a file, unfortunately this change wasn't made in the 1.7.2 branch:

        public OutputResourceBean(){
        ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
        try

        { imgResource = new ByteArrayResource( toByteArray( context.getResourceAsStream( RESOURCE_PATH + "logo.jpg"))); pdfResource = new ByteArrayResource( toByteArray( context.getResourceAsStream( RESOURCE_PATH + "WP_Security_Whitepaper.pdf"))); pdfResourceDynFileName = new ByteArrayResource( toByteArray( context.getResourceAsStream( RESOURCE_PATH + "WP_Security_Whitepaper.pdf"))); }

        catch(Exception e)

        { e.printStackTrace(); }

        }

        Show
        Philip Breau added a comment - I think the sample in the head actually uses the proper non-context-specifc method for creating an output stream from a file, unfortunately this change wasn't made in the 1.7.2 branch: public OutputResourceBean(){ ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); try { imgResource = new ByteArrayResource( toByteArray( context.getResourceAsStream( RESOURCE_PATH + "logo.jpg"))); pdfResource = new ByteArrayResource( toByteArray( context.getResourceAsStream( RESOURCE_PATH + "WP_Security_Whitepaper.pdf"))); pdfResourceDynFileName = new ByteArrayResource( toByteArray( context.getResourceAsStream( RESOURCE_PATH + "WP_Security_Whitepaper.pdf"))); } catch(Exception e) { e.printStackTrace(); } }
        Hide
        Deryk Sinotte added a comment -

        Adjusting priorities and assigning to Ken for re-assignment.

        Show
        Deryk Sinotte added a comment - Adjusting priorities and assigning to Ken for re-assignment.

          People

          • Assignee:
            Patrick Corless
            Reporter:
            Deryk Sinotte
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: