MyFaces Tomahawk
  1. MyFaces Tomahawk
  2. TOMAHAWK-33

Tomahawk's use of HttpServletRequest breaks JSF Portlets

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.8
    • Component/s: Portlet_Support
    • Labels:
      None

      Description

      I have a report of a user who wanted to use JSCookMenu in a portlet. This results in a ClassCastException because org.apache.myfaces.component.html.util.AddResource assumes that the underlying request object will be an HttpServletRequest.

      I will fix this for AddResource, but I suspect that there are other offending classes in Tomahawk.

      For future reference, you should always use methods from ExternalContext instead of doing (HttpServletRequest)ExternalContext.getRequest().

      If you MUST use features of HttpServletRequest that ExternalContext doesn't offer then you should use the PortletUtil to make sure that you don't break portlets. To tell if you are running in a portlet environment, you can say:

      org.apache.myfaces.portlet.PortletUtil.isPortletRequest(FacesContext facesContext)

      Note: calling PortletUtil does not put any dependency on the Portlet API.

      1. AddResource.239380.patch
        4 kB
        Thomas Heute
      2. AddResource.patch
        2 kB
        Blazej Kepa

        Issue Links

          Activity

          Hide
          Leonardo Uribe added a comment -

          Many of the references mentioned here where solved on MYFACES-434, or committed with reference to this issue, but this one was never closed, so I'm closing this one now, since all parts mentioned where changed to work in portlets before release of 1.1.8.

          Show
          Leonardo Uribe added a comment - Many of the references mentioned here where solved on MYFACES-434 , or committed with reference to this issue, but this one was never closed, so I'm closing this one now, since all parts mentioned where changed to work in portlets before release of 1.1.8.
          Hide
          Mike Kienenberger added a comment -

          Blazej Kepa,

          Your patch looks great. Unfortunately, it's no longer valid. I couldn't determine where to apply it. Please provide an updated version. In the future, it would be helpful to create patches with fully-qualified paths relative to the root of the project.

          Show
          Mike Kienenberger added a comment - Blazej Kepa, Your patch looks great. Unfortunately, it's no longer valid. I couldn't determine where to apply it. Please provide an updated version. In the future, it would be helpful to create patches with fully-qualified paths relative to the root of the project.
          Hide
          Blazej Kepa added a comment -

          I have partially fixed this issue by adding support for RenderRequest to addAdditionalInfoToHeader method. When RenderRequest is passed then scripts and resources are rendered in body section (can't find a way to add them to html head section, is there any?)

          Show
          Blazej Kepa added a comment - I have partially fixed this issue by adding support for RenderRequest to addAdditionalInfoToHeader method. When RenderRequest is passed then scripts and resources are rendered in body section (can't find a way to add them to html head section, is there any?)
          Hide
          Rob Raymond added a comment -

          I ran into a similar issue with t:tabbedPane but the offending cast to HttpServletRequest was in
          addAdditionalHeaderInfoToRender() of AddResource.java . Since this method is manipulating the header and that is not possible in a portal, the right thing might be to check if isPortalRequest and do nothing.

          Show
          Rob Raymond added a comment - I ran into a similar issue with t:tabbedPane but the offending cast to HttpServletRequest was in addAdditionalHeaderInfoToRender() of AddResource.java . Since this method is manipulating the header and that is not possible in a portal, the right thing might be to check if isPortalRequest and do nothing.
          Hide
          Kevin Liang added a comment -

          I'm trying to put the htmlEditor on Liferay 3.6 to see if it works. Then I hit the exact problem.
          We're using Liferay to develop some portal applications. JSF is definitely the right direction to go. I'd highly appreciate if the Myfaces team could port all components on to portlet container ASAP. Thanks.

          Show
          Kevin Liang added a comment - I'm trying to put the htmlEditor on Liferay 3.6 to see if it works. Then I hit the exact problem. We're using Liferay to develop some portal applications. JSF is definitely the right direction to go. I'd highly appreciate if the Myfaces team could port all components on to portlet container ASAP. Thanks.
          Hide
          Stan Silvert added a comment -

          Patch committed. Thanks to Thomas Heute of JBoss.

          Show
          Stan Silvert added a comment - Patch committed. Thanks to Thomas Heute of JBoss.
          Hide
          Thomas Heute added a comment -

          Patch that partially covers fixing of AddResource.java

          Show
          Thomas Heute added a comment - Patch that partially covers fixing of AddResource.java

            People

            • Assignee:
              Stan Silvert
              Reporter:
              Stan Silvert
            • Votes:
              6 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development