简体   繁体   English

使用Gatein,JBoss 5.1.0 GA Portlet Bridge Jar和Richfaces错误页面重定向以及我的错误

[英]Richfaces error page redirection with gatein, jboss 5.1.0 ga portlet bridge jars and my mistakes

i know there are a lot of similar questions out there about the same/similar topics but i could not apply any of the solutions to my problem. 我知道关于相同/相似的主题有很多相似的问题,但是我无法对我的问题应用任何解决方案。

I want to redirect user to a custom error page whenever an exception caught while rendering the portlet page. 我想在呈现Portlet页面时捕获到异常时将用户重定向到自定义错误页面。 why exception thrown while rendering the page ? 为什么渲染页面时抛出异常? Its because in the background we throw it to give user some useful information, designed that way and not going to be changed anytime soon, so my intention is to keep it that way. 这是因为在后台我们将其扔给用户一些有用的信息,以这种方式设计并且不会在短期内进行更改,因此我的目的是保持这种方式。

I belive it would be better if i give examples: This is simple portlet that i provide use name and press ">>" button to get some information about that user, in the previous implementation its working fine see the second picture.. 我相信,如果我举个例子,那就更好了:这是我提供使用名称并按“ >>”按钮获取有关该用户的一些信息的简单Portlet,在先前的实现中,它的工作原理很好,请参见第二张图片。

在此处输入图片说明

Second picture: 第二张图片:

as you can see layout is correct""(this is how it looked) the error page has simply replaced the portlet content with its own content and the error message that why we could not get any information about the user. 如您所见,布局是正确的”(这是它的外观),错误页面只是用自己的内容替换了portlet内容,并显示了为什么我们无法获得有关用户任何信息的错误消息。 So far so good. 到现在为止还挺好。

在此处输入图片说明

Now lets look at the problem case: We have upgraded from jboss 4.2.3 ga to 5.1.0 ga and now GateIn comes into play ground. 现在让我们看一下问题案例:我们已经从jboss 4.2.3 ga升级到5.1.0 ga,现在GateIn开始发挥作用了。 Also there were old jars used to create this view of portlets, now they are all upgraded to newer ones. 还有一些旧的jar用于创建portlet的视图,现在它们都已升级为较新的。 Such as: 如:

(org.richfaces.framework) Richfaces-api 3.3.3-final, 
(org.richfaces.framework) Richfaces-impl 3.3.3-final,
(org.richfaces.framework) Richfaces-ui 3.3.3-final,
(com.sun.faces) jsf-api 2.2.14,
(com.sun.faces) jsf-impl 2.2.14,
(javax-servlet) servlet-api 2.5,
(javax-servlet) jstl 1.2

Gatein version: 3.4

and gatein itself uses jsr168 compatible jars + we have jsf 1.2 version (tags are used in this version). Gatein本身使用了与jsr168兼容的jars +我们有jsf 1.2版本(此版本中使用了标签)。

Problem case: as you can see the the portlet we want to get some user information is broken and merged into domain detailed portlet. 问题案例:正如您所看到的那样,我们想要获取一些用户信息的portlet被破坏并合并到域详细的portlet中。 which looks like a soup. 看起来像汤

The code that generates this mess is also belongs to us. 产生这种混乱的代码也属于我们。 which was working correctly once, however its now somehow destroying the whole layout. 它曾经可以正常工作,但是现在却以某种方式破坏了整个布局。

在此处输入图片说明

Let me show you the code that is rendering the views: 让我向您展示渲染视图的代码:

    public void renderView(FacesContext context, UIViewRoot viewToRender) throws java.io.IOException, javax.faces.FacesException{
    try {
        super.renderView(context, viewToRender);
    }catch(FacesException e){         

        Application application = context.getApplication();
        ViewHandler viewhandler = application.getViewHandler();
        PortletRequest request = (PortletRequest)context.getExternalContext().getRequest();
        PortletConfig config = (PortletConfig)request.getAttribute(PortletConstants.PORTLET_CONFIG);
        String errorView = config.getInitParameter(PortletConstants.PORTLET_FACES_ERROR_VIEW);

        if(errorView == null || errorView.matches("")){
            errorView = ProvPortletViewHandler.DEFAULT_FACES_ERROR_VIEW;                       
        }

        Throwable cause = e.getCause();
        FacesMessage fm= findProvisioningException(cause);
        if(fm == null)
        {             
            request.setAttribute("ErrorMessage", "Unknown Error occured");
        }
        else
        {
            request.setAttribute("ErrorMessage", fm.getSummary());
        } 

        viewToRender = viewhandler.createView(context,errorView);         
        context.setViewRoot(viewToRender);             
        viewhandler.renderView(context, viewToRender);

        PortletSession objSes = (PortletSession)context.getExternalContext().getSession(false);
        objSes.invalidate();
    }
}

In this piece of code, you can see that there is super.renderView(context, viewToRender); 在这段代码中,您可以看到存在super.renderView(context, viewToRender);

It goes all the way to the services and makes the service call. 它一直到达服务并进行服务调用。 service calls returns an exception that this user has not information in DB. 服务调用返回此用户在数据库中没有信息的异常。 and this exception is converted into FacesException on the road (we are doing it). 并且此异常会在路上转换为FacesException(我们正在这样做)。

The problem is not the exception its nor converting it to a FacesException. 问题不是异常,也不是将其转换为FacesException。

The problem occurs in this part 此部分出现问题

 viewToRender = viewhandler.createView(context,errorView);         
 context.setViewRoot(viewToRender);             
 viewhandler.renderView(context, viewToRender);

as far as we debugged. 据我们调试。 We belive somehow the old view which was partially rendered due to exception cannot be replaced with the error view. 我们相信,由于异常而部分渲染的旧视图无法替换为错误视图。

But what could do that if it was working previously. 但是,如果以前可以正常工作,那该怎么办。 we have not changed this part of the code. 我们尚未更改代码的这一部分。

Is this information enough to throw an idea about the problem ? 这些信息足以引发有关该问题的想法吗? Would you guys need for more details ? 你们需要更多细节吗? What do you think we are doing wrong here? 您认为我们在这里做错了什么?

Thanks & regards 感谢和问候

After looking deep, it is seen that when the request comes, its response is created and filled at this point. 深入研究后,可以看到当请求到达时,此时将创建并填充其响应。 It has already HTML content inside. 它已经具有HTML内容了。 When trying to redirect new jsp file, it appends new HTML elements to the that response. 当尝试重定向新的jsp文件时,它将新的HTML元素添加到该响应中。 Thus HTML elements inside response become obscure to Gate-in. 因此,响应中的HTML元素对于Gate-in变得晦涩难懂。 In order to avoid this problem, resetting response is enough. 为了避免此问题,重置响应就足够了。 It can be done resetting the response buffer, can be seen on the code; 可以完成重置响应缓冲区,在代码上可以看到;

     viewToRender = viewhandler.createView(context, errorView);
     context.setViewRoot(viewToRender);
     **((javax.portlet.RenderResponse) context.getExternalContext().getResponse()).resetBuffer();**
     viewhandler.renderView(context, viewToRender);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gatein 3.4.0最终的Jboss 5.1.0 Portlet状态和JSR186交互,从一个Portlet转到另一个Portlet时无法显示多个Portlet - Gatein 3.4.0 final Jboss 5.1.0 portlets states and JSR186 interaction, Not able to show multiple portlets when going from one portlet to another Websphere门户,jboss portlet桥,jsf,richfaces,facelets-HTTP 500 OK消息-A4J模式面板问题,丰富的工具提示 - Websphere portal, jboss portlet bridge, jsf, richfaces, facelets - HTTP 500 OK message - issue with a4j modal panel, rich tooltip 丰富:GateIn portlet 中的文件上传 - rich:fileUpload within GateIn portlet Portlet-Bridge,Richfaces和ajax4jsf如何一起工作? - How Do Portlet-Bridge, Richfaces and ajax4jsf work together? 如何使JSF 2.2.6和RichFaces 4.5.0在JBoss 4.2.2.GA上工作? - How to make JSF 2.2.6 and RichFaces 4.5.0 work on JBoss 4.2.2.GA? 使用SSL与JBoss AS7中断连接(Richfaces页面) - Connection interrupted using SSL with a JBoss AS7 (Richfaces page) JSF 1.2,Richfaces 3.X和Jboss Server 5.0:添加Richfaces JAR之后,出现错误 - JSF 1.2 , Richfaces 3.X and Jboss Server 5.0 : After Adding Richfaces JAR it's giving Error 无法使向导示例在GateIn 3.1 GA中工作 - Cannot get Wizard Example to work in GateIn 3.1 GA JBoss AS 4上的JSF和Richfaces - JSF and Richfaces on JBoss AS 4 Tomcat上具有JSF和Richfaces的向导Portlet - Wizard Portlet with JSF and Richfaces on Tomcat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM