相关疑难解决方法(0)

什么是视图构建时间?

我是JSF的新手并且正在阅读像这样的一些堆栈答案,我面对视图构建时间的概念.考虑JSF生命周期方案:

在此输入图像描述

如您所见,没有称为视图构建时间的阶段.也许它意味着与恢复视图阶段相同?来自JavaEE教程

在此阶段,JavaServer Faces实现构建页面视图[...]

lifecycle jsf jsf-2

19
推荐指数
1
解决办法
3164
查看次数

处理AJAXified组件的JSF 2.0异常的正确方法是什么?

我已经设置了web.xml,以便任何java.lang.Throwable(即任何未捕获的异常或错误)将转发到错误页面.但是,对于AJAXified组件,异常不会通过此机制路由到错误页面.

我所拥有的测试用例是一个简单CommandButton的操作方法,它总是抛出一个RuntimeException.看起来最好的做法是让action方法捕获异常并添加FacesMessage类型错误严重性.这是人们做的吗?有没有办法配置JSF,以便如果AJAXified组件的支持bean方法抛出异常,可以显示错误页面?

ajax exception-handling jsf-2

13
推荐指数
1
解决办法
2万
查看次数

在JSF错误处理程序中使用ExternalContext.dispatch导致损坏的页面呈现

简化,我的错误处理程序如下所示:

@Override
public void handle() throws FacesException {
    Iterator<ExceptionQueuedEvent> unhandledExceptionQueuedEvents = getUnhandledExceptionQueuedEvents().iterator();
    FacesContext context = FacesContext.getCurrentInstance();

    if (unhandledExceptionQueuedEvents.hasNext()) {
        Throwable exception = unhandledExceptionQueuedEvents.next().getContext().getException();
        unhandledExceptionQueuedEvents.remove();
        context.getExternalContext().dispatch("/error.jsf");
    }

    while (unhandledExceptionQueuedEvents.hasNext()) {
        unhandledExceptionQueuedEvents.next();
        unhandledExceptionQueuedEvents.remove();
    }
}
Run Code Online (Sandbox Code Playgroud)

简化的template.xhtml

<html>
    <f:view>
    <h:head>
    <!-- some stuff here -->
    </h:head>
    <h:body>
        <div id="menu"><!-- menu content --></div>
        <div id="content">
            <ui:insert name="body"></ui:insert>
        </div>
    </h:body>
    </f:view>
</html>
Run Code Online (Sandbox Code Playgroud)

error.xhtml

<html>
<ui:composition template="/template.xhtml">
    <ui:define name="body">
        ERROR
    </ui:define>
</ui:composition>
</html>
Run Code Online (Sandbox Code Playgroud)

但是当渲染error.jsf时,使用ui:composition进行模板化是非常错误的.JSF将template.xhtml渲染到它周围,然后再开始渲染模板.结果是一个页面,菜单呈现两次,所有资源再次包含在页面中间.它的开头看起来像这样:

<div id="menu></div>
<div<?xml version="1.0" encoding="UTF-8" ?="">
    <!-- Page included once more --> …
Run Code Online (Sandbox Code Playgroud)

jsf-2

2
推荐指数
1
解决办法
4626
查看次数

标签 统计

jsf-2 ×3

ajax ×1

exception-handling ×1

jsf ×1

lifecycle ×1