• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in the getParent methode

 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have the following code in the JSP



and following code in the TesTag.java which is my parent Tag



and following code in the child.java file

and my TLd is



I am able to retrive the getParent value and make a call for getUser() of TesTag but the problem
is there is only two level of nesting the loop should execute only two times nad then stop but here
parent variable is not becoming null it is entring in to infinite loop what could be the problem here
am i missing some thing here.

Thanks
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Link traversal is normally in the form of:

parent= (TesTag)parent.getParent();
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the update it is working fine now, but I have a doubt in the Tag execution steps and out put.

I have this code in the TesTag



and this code in the JSP



my doubt is when the control reaches nested tag first it invokes TesTag which should give the out put
some thing like this

hi this is from the CUSTOM testag are you there
Before throwing SkipPageException
Hi Nested Body
Inside The ParentTag are you there
hi this is from the CUSTOM testag are you there
Before throwing SkipPageException
Inside The ParentTag are you there
hi this is from the CUSTOM testag are you there
Before throwing SkipPageException
Inside The ParentTag are you there

But the out put I am getting is

hi this is from the CUSTOM testag are you there Before throwing SkipPageException hi this is from the CUSTOM testag are you there Before throwing SkipPageException hi this is from the CUSTOM testag are youy there Before throwing SkipPageException Hi Nested Body Inside The ParentTag are you there Inside The ParentTag are you there Inside The ParentTag are you there

I am not able to undertsand the out put how the tag is getting executed.

Thanks
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) The outer tag is processed and prints the following:
hi this is from the CUSTOM testag are you there
Before throwing SkipPageException

2) The outer tag calls getJspBody().invoke(null);

3) The middle tag is processed and prints the following:
hi this is from the CUSTOM testag are you there
Before throwing SkipPageException

4) The middle tag calls getJspBody().invoke(null);

5) The inner tag is processed and prints the following:
hi this is from the CUSTOM testag are you there
Before throwing SkipPageException

6) The inner tag calls getJspBody().invoke(null);

7) The inner tag body is displayed: Hi Nested Body

8) The inner tag getJspBody().invoke(null) returns.

9) The inner tag prints its parent info:
Inside The ParentTag are you there
Inside The ParentTag are you there

10) The middle tag getJspBody().invoke(null) returns.

11) The middle tag prints its parent info:
Inside The ParentTag are you there

12) The outer tag getJspBody().invoke(null) returns.
It has no parent so nothing is printed.

Disclaimer:
This was done in haste like many of my other posts, but the general idea is here.
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To (if necessary) make it a little clearer:

"The X tag is processed" should read as:

The X tag's doTag method is invoked.

Also, insert steps 9a, 11a, and 12a to read:

The X tag's doTag method returns.

Standard disclaimer applies.
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the Reply but i have one more doubt in this,let us consider the same code in JSP


in the code below




line a will return the line 2 as the parent for line 1 so we get

Inside The ParentTag are you there
and next enters in to while loop now line b will actually return line 3 as the parent for line 2
so we get
Inside The ParentTag are you there for second time but once again when we call the line b getJspBody.invoke(null)
of line 3 is reached which does not have any further parent tag so it should return null and we should get
Inside The ParentTag are you there only twice but i am getting it thrice how is it possible.

Is my understanding wrong.

Thanks
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"but once again when we call the line b getJspBody.invoke(null)"

This appears to be incorrect since the parent printing occurs after exiting the invoke method. The invoke method is called once for each tag, so I believe it is incorrect to suggest that it is being called again for a particular tag.

I previously posted a 12 step sequence of the program flow. Did you find an error in it (which is possible)? Please try to follow my 12 step post and incorporate the update post that follows it. Then let me know which step you feel is in error.
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Yes we cant call the getJspBody().invoke(null) twice for the same tag that is wrong. here is my understanding

First the inner most tag getJspBody().invoke(null) is called and while loop executes until it reaches its last parent
that is the outer most tag.once Done getJspBody() of inner most tag will return Then next Second innermost Tag will start
getJspBody().invoke will resume and once again executes while loop until it reaches the top most tag once done getJspBody().invoke(null)
of the outer most tag will resume and terminate. thats why we have tree out put statements instead of two

on the same lines instead of three level if we had four level of Tag nesting we would have had 6 out put statements

getJspBody().invoke(null) WILL NOT BE CALLED TWICE ON THE SAME TAG BUT THE WAY IT IS EXECUTING WILL CAUSE THIS BEHAVIOUR that is once called it will make a call to other tags getJspBody().invoke(null) and so once inner tag comppletes the outer tag will continue and so on. am i correct.

Thanks
 
Dee Brown
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First the inner most tag getJspBody().invoke(null) is called and while loop executes until it reaches its last parent that is the outer most tag. Once done, getJspBody() of inner most tag will return. Then next Second innermost Tag will start getJspBody().invoke will resume and once again executes while loop until it reaches the top most tag. Once done getJspBody().invoke(null) of the outer most tag will resume and terminate. thats why we have tree out put statements instead of two


You are describing steps 6 through 12 in my previous post.

on the same lines instead of three level if we had four level of Tag nesting we would have had 6 out put statements


True



getJspBody().invoke(null) WILL NOT BE CALLED TWICE ON THE SAME TAG BUT THE WAY IT IS EXECUTING WILL CAUSE THIS BEHAVIOUR that is once called it will make a call to other tags getJspBody().invoke(null) and so once inner tag [doGet] completes, the outer tag [getJspBody().invoke(null)] will continue [and return] and so on. am i correct.


True (note my [...] insertions).

However, if you understand the program flow then you should be able to understand the 12 steps listed above.
 
raja ram
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply I understood the concept.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic