1

so i have a

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>

and i have an other xhmt file for different purpose on that i am using

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>

my question is that in both files (A and B) i haved used

<p:ajax event="tabChange" />

but in file A.xhtml when i changed the tab listener does not call method(action method of java class) without

  immediate="true"

and in file B.xhtml when i am changing tabs method is calling without

  immediate="true"

can any one makes me understand whats happening ? or why/where we use 'immediate' attribute ? should i post my whole code ?

Mohsin AR
  • 2,998
  • 2
  • 24
  • 36

2 Answers2

3

immediate="true" causes the actions to be invoked in the 'Apply Request Values' phase before any validations/conversions. The tag defaults to false, which makes JSF go through the standard lifecycle and call the actions at 'Invoke Application' phase.

I'm guessing (difficult to get it from your stub example) that you have validation or conversion errors. On an error event, JSF skips the remaining lifecycle phases, so the tabChange event won't be called.

You should try debugging it by creating a <h:messages /> tag on top of the page or checking the stack trace if its logged.

For more information please refer to:

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 Mendoza
  • 85,076
  • 16
  • 154
  • 332
acsadam0404
  • 2,711
  • 1
  • 26
  • 36
  • @Luiggi As a minor remark, though *life cycle* is a right English phrase, typically *lifecycle* word is used in conjunction with a JSF application. See, for example, [Oracle Java EE tutorial](http://docs.oracle.com/javaee/6/tutorial/doc/gjaam.html#gjbnc). – skuntsel Oct 12 '13 at 15:37
  • @skuntsel thanks, I'm aware of that, I just let me guide for my spell checker :). – Luiggi Mendoza Oct 12 '13 at 15:39
  • @adam yeah i got some validation error (in A.xhtml) when i use `` i have used some custom validation if user leaves some inputfields blank on submit button, not on tabchange event, here what should i do ? there is no need of validation in tabChange so its better to use `immediate="true"` ? – Mohsin AR Oct 12 '13 at 21:33
2

For the file A.xhtml their will be a validation error therefore it doesn't call the InvokeApllication phase.

But in B.xhtml their wont be and validation error so it call's the InvokeApplication phase and your managed bean methods are called.

Put <p:message autoUpdate="true" /> in your A.xhtml you might get the error message

where as immediate="true" is to skip the validation phase..

BholaVishwakarma
  • 581
  • 6
  • 18
  • yeah i got some validation error (in A.xhtml) when i use `` i have used some custom validation if user leaves some inputfields blank on submit button, not on tabchange event, here what should i do ? there is no need of validation in tabChange so its better to use `immediate="true"` ? – Mohsin AR Oct 12 '13 at 21:31
  • 2
    Yes so put immediate=true and your done. – BholaVishwakarma Oct 13 '13 at 15:13