简体   繁体   English

理解 JSF 阶段的问题

[英]Problems understanding JSF Phases

I have a problem understanding the JSF Phases.我在理解 JSF 阶段时遇到问题。 I have the followed problem.我有以下问题。

On my main page i create a panelGroup, and includes a xhtml dynamicaly.在我的主页上,我创建了一个 panelGroup,并动态包含了一个 xhtml。

    <h:panelGroup id="padding">
        <ui:include src="#{navigationHandler.currentPage}" />
    </h:panelGroup>

In my menubar i have some code like this:在我的菜单栏中,我有一些这样的代码:

    <p:submenu label="#{translator.menuentry_insured}">
        <p:menuitem value="#{translator.menuentry_add_insured}"    actionListener="#{navigationHandler.addInsured}"    update=":padding" />
        <p:menuitem value="#{translator.menuentry_search_insured}" actionListener="#{navigationHandler.searchInsured}" update=":padding"/>
    </p:submenu>

When I click on the menuitem, first the "currentPage" method is called, returning the page currently active.当我点击菜单项时,首先调用“currentPage”方法,返回当前活动的页面。 After that, the actionListener is called, setting the page to the new page.之后,调用 actionListener,将页面设置为新页面。 If I click again on the same link, then the correct page is shown.如果我再次单击同一链接,则会显示正确的页面。

I know the problem is in the JSF lifecycle ("restore view" phase before "invoke application" phase), but I don't know how to solve this.我知道问题出在 JSF 生命周期(“调用应用程序”阶段之前的“恢复视图”阶段),但我不知道如何解决这个问题。

Here is a output from my own PhaseListener, just for debugging purpose:这是来自我自己的 PhaseListener 的 output,仅用于调试目的:

BEFORE: RESTORE_VIEW 1
    Using current page: addInsured.xhtml
AFTER: RESTORE_VIEW 1
BEFORE: APPLY_REQUEST_VALUES 2
AFTER: APPLY_REQUEST_VALUES 2
BEFORE: PROCESS_VALIDATIONS 3
AFTER: PROCESS_VALIDATIONS 3
BEFORE: UPDATE_MODEL_VALUES 4
AFTER: UPDATE_MODEL_VALUES 4
BEFORE: INVOKE_APPLICATION 5
    Setting current page to searchInsured.xhtml
AFTER: INVOKE_APPLICATION 5
BEFORE: RENDER_RESPONSE 6
AFTER: RENDER_RESPONSE 6

Is there any solution?有什么解决办法吗? What I am doing wrong?我做错了什么?

I believe you are confusing JSF Components (usually seen with prefixs of 'h', 'f', 'p') with facelet components (usually seen with prefix of 'ui').我相信您将 JSF 组件(通常带有前缀“h”、“f”、“p”)与 facelet 组件(通常带有前缀“ui”)混淆了。 They aren't the same thing.他们不是一回事。 JSF Component usually become part of the tree and participate in the JSF phases. JSF 组件通常成为树的一部分并参与 JSF 阶段。 Facelet component only exist during RESTORE_VIEW . Facelet 组件仅在RESTORE_VIEW期间存在。 I usually think of facelet components as preprocessors.我通常将 facelet 组件视为预处理器。 They normally generate JSF components.它们通常生成 JSF 组件。

In your example, <ui:include src="#{navigationHandler.currentPage}" /> is replaced with whatever JSF Components specified in the source file referred to by navigationHandler.currentPage at the time of RESTORE_VIEW .在您的示例中, <ui:include src="#{navigationHandler.currentPage}" />替换为在RESTORE_VIEW时由navigationHandler.currentPage引用的源文件中指定的任何 JSF 组件。 After RESTORE_VIEW , there is no more <ui:include /> , so it isn't re-evaluated and doesn't update.RESTORE_VIEW之后,没有更多的<ui:include /> ,因此不会重新评估并且不会更新。

During INVOKE_APPLICATION , navigationHandler.currentPage is updated, but the component tree is still the same.INVOKE_APPLICATION期间, navigationHandler.currentPage会更新,但组件树仍然相同。 If you could force a self redirect during INVOKE_APPLICATION , then the lifecycle would be restarted and <ui:include src="#{navigationHandler.currentPage}"/> would be re-evaluated.如果您可以在INVOKE_APPLICATION期间强制进行自我重定向,则生命周期将重新启动并且<ui:include src="#{navigationHandler.currentPage}"/>将重新评估。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM