【问题标题】:How to debug missing resource/reference on xhmtl?如何调试 xhmtl 上缺少的资源/引用?
【发布时间】:2016-03-31 05:14:59
【问题描述】:

有时我的过滤器出现异常,如下所示: chain.doFilter(request, response);

而且,经过长时间的搜索,我会发现在另一个 xhtml 文件中引用的某些 xhtml 文件丢失了,或者没有在 faces-config.xml 中声明。

我通过删除 xhtml 文件的元素来搜索问题并查看异常停止发生的位置。

有没有更好的调试方法?

【问题讨论】:

  • 在 faces-config.xml 中有 吗?
  • @BalusC 一旦我看到一个非常糟糕的自定义,一切都通过过滤器。一旦它被修复调试变得容易
  • @MahendranAyyarsamyKandiar 不,我没有。
  • 尝试添加一个并重定向到可以访问异常的错误页面
  • @MahendranAyyarsamyKandiar 确实有效!谢谢!请将其发布为答案。

标签: debugging jsf jakarta-ee xhtml


【解决方案1】:

添加处理异常的异常处理器工厂,并重定向或转发到错误页面或登录页面。

良好的登录将帮助您轻松找到错误并帮助您更快地解决问题。

web.xml:

<factory>
    <exception-handler-factory>com.framework.exceptionmgmt.CustomExceptionHandlerFactory</exception-handler-factory>
</factory>

工厂:

@Override
public ExceptionHandler getExceptionHandler() {
    return new CustomExceptionHandler(wrapped.getExceptionHandler());
}

/**
 * Returns the wrapped factory.
 */
@Override
public ExceptionHandlerFactory getWrapped() {
    return wrapped;
}

处理程序:

 @Override
public void handle() throws FacesException {
    for (final Iterator<ExceptionQueuedEvent> it = getUnhandledExceptionQueuedEvents().iterator(); it.hasNext();) {
        Throwable t = it.next().getContext().getException();
        System.out.println("Exception in page: "+t.getMessage());
        while ((t instanceof FacesException || t instanceof EJBException || t instanceof ELException) && t.getCause() != null) {
            t = t.getCause();
        }

        if (t instanceof FileNotFoundException || t instanceof ViewExpiredException) {

            final ExternalContext externalContext = facesContext.getExternalContext();
            final Map<String, Object> requestMap = externalContext.getRequestMap();
            try {
                // Log the information in the logs
                String message;
                if (t instanceof ViewExpiredException) {
                    final String viewId = ((ViewExpiredException) t).getViewId();
                    message = "View is expired. <a href='/ifos" + viewId + "'>Back</a>";
                } else {
                    message = t.getMessage(); // beware, don't leak internal
                                              // info!
                }
                requestMap.put("errorMsg", message);
                try {

                    HttpServletRequest origRequest = (HttpServletRequest) facesContext.getExternalContext()
                            .getRequest();
                    String requestedURL = origRequest.getRequestURL().toString();
                    resetResponse(facesContext);
                    redirectToCorrectPage(origRequest.getContextPath()+"/error.xhtml",facesContext);

                } catch (final IOException e) {
                }
                facesContext.responseComplete();
            } finally {
                it.remove();
            }
        }else{
            try {
            resetResponse(facesContext);
                Map<String, Object> sessnMap = FacesContext
                        .getCurrentInstance().getExternalContext()
                        .getSessionMap();

                // For checking whether user is logged in or not If not then redirect to login page instead of error page
                Boolean isUserLoggedIn = (Boolean) sessnMap
                        .get("isUserLoggedIn");
                if (isUserLoggedIn == null || !isUserLoggedIn) {
                    redirectToCorrectPage(
                            ((HttpServletRequest) facesContext
                                    .getExternalContext().getRequest()).getContextPath()
                                    + "/error.xhtml",
                            facesContext);
                } else {
                    redirectToCorrectPage(
                            ((HttpServletRequest) facesContext
                                    .getExternalContext().getRequest()).getContextPath()
                                    + "/error.xhtml",
                            facesContext);
                }
            } catch (final IOException e) {
            }finally {
                it.remove();
            }
            facesContext.responseComplete();
        }
    }

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-17
  • 2013-04-13
相关资源
最近更新 更多