You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Stan Silvert (JIRA)" <in...@incubator.apache.org> on 2005/03/09 22:47:56 UTC

[jira] Created: (MYFACES-123) UIComponentTag breaks Portlet support: ClassCastException

UIComponentTag breaks Portlet support: ClassCastException
---------------------------------------------------------

         Key: MYFACES-123
         URL: http://issues.apache.org/jira/browse/MYFACES-123
     Project: MyFaces
        Type: Bug
    Versions: Nightly Build    
    Reporter: Stan Silvert
    Priority: Blocker


UIComponentTag now has code that calls ExternalContext.getRequest() and then casts the result to a ServletRequest.  In a portal environment, the underlying request is not an instance of ServletRequest, so you get a ClassCastException.

Here is the offending code from the setupResponseWriter() method in UIComponentTag:

ServletRequest request = (ServletRequest)facesContext.getExternalContext().getRequest();

_writer = renderKit.createResponseWriter(new _PageContextOutWriter(pageContext),
                                         request.getContentType(), //TODO: is this the correct content type?
                                         request.getCharacterEncoding());

I see two ways to fix this:
1) Just pass nulls to createResponseWriter instead of getting content type and char encoding from the request.  This is allowed under the JSF API, but I'm not sure if it is what you want.
2) Call PortletUtil.isRenderResponse(FacesContext) to find out if we are in a portlet environment.  Then use the Portlet API or Servlet API to get the content type and char encoding.  For portlet, you would need to use the RenderResponse like this:

if (PortletUtil.isRenderResponse(facesContext)) 
{
   RenderResponse response = (RenderResponse)facesContext.getExternalContext().getResponse();

   response.getContentType();
   response.getCharacterEncoding();
}

Overall, I think we should use #1 if it will work.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


Re: [jira] Commented: (MYFACES-123) UIComponentTag breaks Portlet support: ClassCastException

Posted by Derek Shen <de...@gmail.com>.
It is introduced by some new code change with MyFaces. Stan told me
that without the fix, the portlet support in MyFaces will not work on
any portal.

On Thu, 10 Mar 2005 02:27:54 +0100 (CET), Kito D. Mann (JIRA)
<in...@incubator.apache.org> wrote:
>     [ http://issues.apache.org/jira/browse/MYFACES-123?page=comments#action_60551 ]
> 
> Kito D. Mann commented on MYFACES-123:
> --------------------------------------
> 
> Stan,
> 
> Any idea why things still seem to work with this bug?
> 
> Kito D. Mann
> Author, JavaServer Faces in Action
> http://www.JSFCentral.com - JSF FAQ, news, and info
> 
> Are you using JSF in a project? Send an e-mail to trenches@jsfcentral.com and you could win a free copy of JavaServer Faces in Action!
> 
> > UIComponentTag breaks Portlet support: ClassCastException
> > ---------------------------------------------------------
> >
> >          Key: MYFACES-123
> >          URL: http://issues.apache.org/jira/browse/MYFACES-123
> >      Project: MyFaces
> >         Type: Bug
> >     Versions: Nightly Build
> >     Reporter: Stan Silvert
> >     Priority: Blocker
> 
> >
> > UIComponentTag now has code that calls ExternalContext.getRequest() and then casts the result to a ServletRequest.  In a portal environment, the underlying request is not an instance of ServletRequest, so you get a ClassCastException.
> > Here is the offending code from the setupResponseWriter() method in UIComponentTag:
> > ServletRequest request = (ServletRequest)facesContext.getExternalContext().getRequest();
> > _writer = renderKit.createResponseWriter(new _PageContextOutWriter(pageContext),
> >                                          request.getContentType(), //TODO: is this the correct content type?
> >                                          request.getCharacterEncoding());
> > I see two ways to fix this:
> > 1) Just pass nulls to createResponseWriter instead of getting content type and char encoding from the request.  This is allowed under the JSF API, but I'm not sure if it is what you want.
> > 2) Call PortletUtil.isRenderResponse(FacesContext) to find out if we are in a portlet environment.  Then use the Portlet API or Servlet API to get the content type and char encoding.  For portlet, you would need to use the RenderResponse like this:
> > if (PortletUtil.isRenderResponse(facesContext))
> > {
> >    RenderResponse response = (RenderResponse)facesContext.getExternalContext().getResponse();
> >    response.getContentType();
> >    response.getCharacterEncoding();
> > }
> > Overall, I think we should use #1 if it will work.
> 
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the administrators:
>   http://issues.apache.org/jira/secure/Administrators.jspa
> -
> If you want more information on JIRA, or have a bug to report see:
>   http://www.atlassian.com/software/jira
> 
>

[jira] Commented: (MYFACES-123) UIComponentTag breaks Portlet support: ClassCastException

Posted by "Stan Silvert (JIRA)" <in...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/MYFACES-123?page=comments#action_60595 ]
     
Stan Silvert commented on MYFACES-123:
--------------------------------------

Actually, I found that it wasn't a problem with a new code change.  It looks like UIComponentTag has not been changed in quite a while.  The problem was that Derek and I were both trying MyFaces on a new portlet implementation (JBoss Portal) which caused a different execution path that hit this problem.

Still, the problem in MyFaces needs to be fixed ASAP.  Now that we have portlet support we can't assume that the underlying request is a ServletRequest.


> UIComponentTag breaks Portlet support: ClassCastException
> ---------------------------------------------------------
>
>          Key: MYFACES-123
>          URL: http://issues.apache.org/jira/browse/MYFACES-123
>      Project: MyFaces
>         Type: Bug
>     Versions: Nightly Build
>     Reporter: Stan Silvert
>     Priority: Blocker

>
> UIComponentTag now has code that calls ExternalContext.getRequest() and then casts the result to a ServletRequest.  In a portal environment, the underlying request is not an instance of ServletRequest, so you get a ClassCastException.
> Here is the offending code from the setupResponseWriter() method in UIComponentTag:
> ServletRequest request = (ServletRequest)facesContext.getExternalContext().getRequest();
> _writer = renderKit.createResponseWriter(new _PageContextOutWriter(pageContext),
>                                          request.getContentType(), //TODO: is this the correct content type?
>                                          request.getCharacterEncoding());
> I see two ways to fix this:
> 1) Just pass nulls to createResponseWriter instead of getting content type and char encoding from the request.  This is allowed under the JSF API, but I'm not sure if it is what you want.
> 2) Call PortletUtil.isRenderResponse(FacesContext) to find out if we are in a portlet environment.  Then use the Portlet API or Servlet API to get the content type and char encoding.  For portlet, you would need to use the RenderResponse like this:
> if (PortletUtil.isRenderResponse(facesContext)) 
> {
>    RenderResponse response = (RenderResponse)facesContext.getExternalContext().getResponse();
>    response.getContentType();
>    response.getCharacterEncoding();
> }
> Overall, I think we should use #1 if it will work.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


[jira] Commented: (MYFACES-123) UIComponentTag breaks Portlet support: ClassCastException

Posted by "Kito D. Mann (JIRA)" <in...@incubator.apache.org>.
     [ http://issues.apache.org/jira/browse/MYFACES-123?page=comments#action_60551 ]
     
Kito D. Mann commented on MYFACES-123:
--------------------------------------

Stan,

Any idea why things still seem to work with this bug?

Kito D. Mann 
Author, JavaServer Faces in Action
http://www.JSFCentral.com - JSF FAQ, news, and info

Are you using JSF in a project? Send an e-mail to trenches@jsfcentral.com and you could win a free copy of JavaServer Faces in Action!


> UIComponentTag breaks Portlet support: ClassCastException
> ---------------------------------------------------------
>
>          Key: MYFACES-123
>          URL: http://issues.apache.org/jira/browse/MYFACES-123
>      Project: MyFaces
>         Type: Bug
>     Versions: Nightly Build
>     Reporter: Stan Silvert
>     Priority: Blocker

>
> UIComponentTag now has code that calls ExternalContext.getRequest() and then casts the result to a ServletRequest.  In a portal environment, the underlying request is not an instance of ServletRequest, so you get a ClassCastException.
> Here is the offending code from the setupResponseWriter() method in UIComponentTag:
> ServletRequest request = (ServletRequest)facesContext.getExternalContext().getRequest();
> _writer = renderKit.createResponseWriter(new _PageContextOutWriter(pageContext),
>                                          request.getContentType(), //TODO: is this the correct content type?
>                                          request.getCharacterEncoding());
> I see two ways to fix this:
> 1) Just pass nulls to createResponseWriter instead of getting content type and char encoding from the request.  This is allowed under the JSF API, but I'm not sure if it is what you want.
> 2) Call PortletUtil.isRenderResponse(FacesContext) to find out if we are in a portlet environment.  Then use the Portlet API or Servlet API to get the content type and char encoding.  For portlet, you would need to use the RenderResponse like this:
> if (PortletUtil.isRenderResponse(facesContext)) 
> {
>    RenderResponse response = (RenderResponse)facesContext.getExternalContext().getResponse();
>    response.getContentType();
>    response.getCharacterEncoding();
> }
> Overall, I think we should use #1 if it will work.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira