【问题标题】:where we use immediate="true" [duplicate]我们在哪里使用 immediate="true" [重复]
【发布时间】:2013-10-20 03:56:35
【问题描述】:

所以我有一个

A.xhtml

<p:tabView id="headOfAccountsId_tabview">
<p:tab title="Main Head Of Accounts" id="mainHeadOfAccountsId_tab">
 // completely finished with codes 
 // here i have done some inputtext fields with jsf validation , 
 // and submit button to call action on ajax
 // and p:datatable to view only records and user can edit and delete record on ajax
</p:tab>
<p:tab title="Sub Head Of Accounts" id="subHeadOfAccountsId_tab">
 // just have open and closing tags of p:tab i meant i will do code later here 
</p:tab>
</p:tabView>

我还有另一个 xhmt 文件用于我正在使用的不同目的

B.xhtml

 // all the input fields outside the <p:tabView >
 // here i have done some inputtext fields with jsf validation , 
 // and submit button to call action on ajax
<p:tabView >
<p:tab>
 //p:datatable to view only records
</p:tab>
<p:tab>
//p:datatable to view only records
</p:tab>
</p:tabView>

我的问题是我在两个文件(A 和 B)中都使用过

<p:ajax event="tabChange" />

但在文件 A.xhtml 中,当我更改选项卡侦听器时,不会调用方法(java 类的操作方法)而没有

  immediate="true"

当我更改选项卡时,在文件 B.xhtml 中调用的方法没有

  immediate="true"

谁能让我明白发生了什么?或者我们为什么/在哪里使用“立即”属性? 我应该发布我的整个代码吗?

【问题讨论】:

    标签: jsf jsf-2 primefaces datatable


    【解决方案1】:

    immediate="true" 导致在任何验证/转换之前的“应用请求值”阶段调用操作。该标记默认为 false,这使 JSF 经历标准生命周期并在“调用应用程序”阶段调用操作。

    我猜(很难从您的存根示例中得到它)您有验证或转换错误。在发生错误事件时,JSF 会跳过剩余的生命周期阶段,因此不会调用 tabChange 事件。

    您应该尝试通过在页面顶部创建 &lt;h:messages /&gt; 标记或检查堆栈跟踪(如果已记录)来调试它。

    更多信息请参考:

    http://www.javacodegeeks.com/2012/01/jsf-and-immediate-attribute-command.html

    http://docs.oracle.com/javaee/6/tutorial/doc/bnaqq.html

    http://balusc.blogspot.hu/2006/09/debug-jsf-lifecycle.html#AddImmediateTrueToUIInputOnly

    【讨论】:

    • @Luiggi 作为一个小评论,虽然 lifecycle 是一个正确的英文短语,但通常 lifecycle 词与 JSF 应用程序一起使用。例如,请参阅Oracle Java EE tutorial
    • @skuntsel 谢谢,我知道了,我只是让我指导我的拼写检查器:)。
    • @adam 是的,当我使用 &lt;p:messages autoUpdate="true" /&gt; 时,我遇到了一些验证错误(在 A.xhtml 中),如果用户在提交按钮上将一些输入字段留空,而不是在 tabchange 事件上,我使用了一些自定义验证,在这里我该怎么办 ? tabChange 中不需要验证,所以最好使用immediate="true"
    【解决方案2】:

    对于文件 A.xhtml,它们将是一个验证错误,因此它不会调用 InvokeApllication 阶段。

    但在 B.xhtml 中它们不会出现验证错误,因此它调用 InvokeApplication 阶段并调用您的托管 bean 方法。

    &lt;p:message autoUpdate="true" /&gt; 在您的 A.xhtml 中您可能会收到错误消息

    immediate="true" 是跳过验证阶段..

    【讨论】:

    • 是的,当我使用&lt;p:messages autoUpdate="true" /&gt; 时,我遇到了一些验证错误(在 A.xhtml 中),如果用户在提交按钮上将一些输入字段留空,而不是在 tabchange 事件上,我使用了一些自定义验证,这里应该我愿意 ? tabChange 中不需要验证,所以最好使用immediate="true"
    • 是的,所以输入 immediate=true 就可以了。
    猜你喜欢
    • 1970-01-01
    • 2012-04-09
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-13
    • 1970-01-01
    相关资源
    最近更新 更多