You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jim Menard <ji...@io.com> on 2003/12/13 16:55:09 UTC
Life cycle and a mystery
After getting quite far in my app development, I now have to understand
a component's life cycle, if that's the correct term. I've started
reading the Developer's Guide more closely.
Here's my mystery: I have a log out component that contains a form, a
"Log Out" LinkSubmit, and an "Insert" that displays the username. This
component is inside another component that wraps the log out inside a
Conditional that makes sure the user is logged in. After I log in, the
log out component displays correctly. However, when I click on the link
to log out an exception is raised because the log out component tries
to access the user name but the user object is now null.
Why is the log out component and its Insert even being accessed? It's
wrapped inside a Conditional that is false when the user is logged out,
so it should never try to access the user name.
I can work around this problem by adding an additional Conditional
around the username Insert itself, but this seems redundant. The log
out component shouldn't be accessed at all because of the outer
component's Conditional. Why do I need the same Conditional inside the
log out component?
Thank you for your help. I can post the .html and .jwc files if my
explanation is too confusing.
Jim
--
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"Never anthropomorphize computers. They hate that." -- Ricdude on
slashdot
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Life cycle and a mystery
Posted by Jim Menard <ji...@io.com>.
> Sorry, I'm equally stumped... I can't see what would cause this
> behavior. If I had to debug this, I'd stick breakpoints or logging
> statements in the various methods to see what was happening. I'd
> change
> the expression="page.visit.member.username" to "username" and add a
> getUsername() method so I could do the same debugging there.
Thanks. I'll try that.
Jim
--
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"If you ever fear that machines will surpass humans in intelligence,
just ask Microsoft to write the OS."
-- pieceoftheuniverse in rec.humor.oracle.d
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Life cycle and a mystery
Posted by Bryan Lewis <br...@maine.rr.com>.
Sorry, I'm equally stumped... I can't see what would cause this
behavior. If I had to debug this, I'd stick breakpoints or logging
statements in the various methods to see what was happening. I'd change
the expression="page.visit.member.username" to "username" and add a
getUsername() method so I could do the same debugging there.
----- Original Message -----
From: "Jim Menard" <ji...@io.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Tuesday, December 16, 2003 3:58 PM
Subject: Re: Life cycle and a mystery
>
> On Dec 16, 2003, at 3:51 PM, Bryan Lewis wrote:
>
> > Could I see the isLoggedIn() or getLoggedIn() method of your custom
> > Visit class?
>
>
> public Member getMember() { return member; }
> public void setMember(Member m) { member = m; }
> public void logOut() { setMember(null); }
> public boolean isLoggedIn() { return member != null; }
>
> > I'm guessing the following:
> > The first ifLoggedIn conditional evaluates the expression
> > "page.visit.loggedIn", which will automatically create a Visit
object
> > when it doesn't exist, that is, when the user isn't logged in. When
> > the
> > second conditional is encountered, the Visit object exists.
>
> The problem happens when the user is logging out. The visit already
> exists. It isn't destroyed when the user logs out, unless Tapestry is
> doing something strange behind my back.
>
> > The
> > isLoggedIn() method might behave differently in those two cases.
(This
> > side effect is why my loggedIn method uses page.engine.visit, to
avoid
> > the auto-creation.)
>
> Jim
> --
> Jim Menard, jimm@io.com, http://www.io.com/~jimm/
> "Space Opera. It's not over until the fat lady explosively
> decompresses..."
> -- Matt Ruff / Lisa Gold, rec.arts.sf.written
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Life cycle and a mystery
Posted by Jim Menard <ji...@io.com>.
On Dec 16, 2003, at 3:51 PM, Bryan Lewis wrote:
> Could I see the isLoggedIn() or getLoggedIn() method of your custom
> Visit class?
public Member getMember() { return member; }
public void setMember(Member m) { member = m; }
public void logOut() { setMember(null); }
public boolean isLoggedIn() { return member != null; }
> I'm guessing the following:
> The first ifLoggedIn conditional evaluates the expression
> "page.visit.loggedIn", which will automatically create a Visit object
> when it doesn't exist, that is, when the user isn't logged in. When
> the
> second conditional is encountered, the Visit object exists.
The problem happens when the user is logging out. The visit already
exists. It isn't destroyed when the user logs out, unless Tapestry is
doing something strange behind my back.
> The
> isLoggedIn() method might behave differently in those two cases. (This
> side effect is why my loggedIn method uses page.engine.visit, to avoid
> the auto-creation.)
Jim
--
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"Space Opera. It's not over until the fat lady explosively
decompresses..."
-- Matt Ruff / Lisa Gold, rec.arts.sf.written
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Life cycle and a mystery
Posted by Bryan Lewis <br...@maine.rr.com>.
Could I see the isLoggedIn() or getLoggedIn() method of your custom
Visit class? I'm guessing the following:
The first ifLoggedIn conditional evaluates the expression
"page.visit.loggedIn", which will automatically create a Visit object
when it doesn't exist, that is, when the user isn't logged in. When the
second conditional is encountered, the Visit object exists. The
isLoggedIn() method might behave differently in those two cases. (This
side effect is why my loggedIn method uses page.engine.visit, to avoid
the auto-creation.)
Just a guess for now.
----- Original Message -----
From: "Jim Menard" <ji...@io.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Monday, December 15, 2003 9:47 PM
Subject: Re: Life cycle and a mystery
> Bryan,
>
> > I have a similar component and haven't seen a problem like this. As
> > you
> > suggested, posting your files would help. I'm guessing it's
something
> > in the java code. Here's mine, with the presentation stuff stripped
> > out
> > for simplicity:
>
> OK, here's a section of the HTML which is the "LeftSide" component in
> my page wrapper. This is the outer component. You need to see the
outer
> component and the inner component because the cause of my confusion is
> that the outer component uses a conditional that SHOULD prevent the
> inner component's expressions (included below) from being evaluated
> when logged in.
>
> <span jwcid="ifLoggedIn">
> <a jwcid="logOutForm">Log Out</a><br>
> </span>
>
> Here are the relevant parts of LeftSide.jwc:
>
> <component-specification
> class="org.apache.tapestry.BaseComponent"
> allow-informal-parameters="no">
> <component id="ifLoggedIn" type="Conditional">
> <binding name="condition" expression="page.visit.loggedIn"/>
> </component>
> <component id="logOutForm" type="LogoutForm"/>
> </component-specification>
>
> Now here's LogoutForm.html in its entirety. Note that without the
> "ifLoggedIn" conditional here, I see a null property exception (I'll
> explain when I dump the .jwc below).
>
> <form jwcid="logoutForm">
> <a jwcid="logOutLink">Log Out</a>
> <span jwcid="ifLoggedIn">
> <span jwcid="username">username</span>
> </span>
> </form>
>
> Here's LogoutForm.jwc. The expression that causes the problem is the
> username (page.visit.member.username). When the user is logged out,
> then member is null and that's what's causing the exception. WHY
> doesn't the outer conditional (in LeftSide above) prevent the username
> component from being evaluated? Why do I have to repeat the
conditional
> in this LogoutForm?
>
> <component-specification
>
class="com.preclick.photowiki.tapestry.components.LogoutWidget"
> allow-informal-parameters="no">
> <component id="ifLoggedIn" type="Conditional">
> <binding name="condition" expression="page.visit.loggedIn"/>
> </component>
> <component id="logoutForm" type="Form">
> <binding name="listener" expression="listeners.logout"/>
> </component>
> <component id="logOutLink" type="LinkSubmit">
> <binding name="listener" expression="listeners.logout"/>
> </component>
> <component id="username" type="Insert">
> <binding name="value" expression="page.visit.member.username"/>
> </component>
> </component-specification>
>
> Jim
> --
> Jim Menard, jimm@io.com, http://www.io.com/~jimm/
> "Congratulations are in order for Tom Reid. He says he just found out
> he is
> the winner of the 2021 Psychic of the Year award." -- Seen on slashdot
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Life cycle and a mystery
Posted by Jim Menard <ji...@io.com>.
Bryan,
> I have a similar component and haven't seen a problem like this. As
> you
> suggested, posting your files would help. I'm guessing it's something
> in the java code. Here's mine, with the presentation stuff stripped
> out
> for simplicity:
OK, here's a section of the HTML which is the "LeftSide" component in
my page wrapper. This is the outer component. You need to see the outer
component and the inner component because the cause of my confusion is
that the outer component uses a conditional that SHOULD prevent the
inner component's expressions (included below) from being evaluated
when logged in.
<span jwcid="ifLoggedIn">
<a jwcid="logOutForm">Log Out</a><br>
</span>
Here are the relevant parts of LeftSide.jwc:
<component-specification
class="org.apache.tapestry.BaseComponent"
allow-informal-parameters="no">
<component id="ifLoggedIn" type="Conditional">
<binding name="condition" expression="page.visit.loggedIn"/>
</component>
<component id="logOutForm" type="LogoutForm"/>
</component-specification>
Now here's LogoutForm.html in its entirety. Note that without the
"ifLoggedIn" conditional here, I see a null property exception (I'll
explain when I dump the .jwc below).
<form jwcid="logoutForm">
<a jwcid="logOutLink">Log Out</a>
<span jwcid="ifLoggedIn">
<span jwcid="username">username</span>
</span>
</form>
Here's LogoutForm.jwc. The expression that causes the problem is the
username (page.visit.member.username). When the user is logged out,
then member is null and that's what's causing the exception. WHY
doesn't the outer conditional (in LeftSide above) prevent the username
component from being evaluated? Why do I have to repeat the conditional
in this LogoutForm?
<component-specification
class="com.preclick.photowiki.tapestry.components.LogoutWidget"
allow-informal-parameters="no">
<component id="ifLoggedIn" type="Conditional">
<binding name="condition" expression="page.visit.loggedIn"/>
</component>
<component id="logoutForm" type="Form">
<binding name="listener" expression="listeners.logout"/>
</component>
<component id="logOutLink" type="LinkSubmit">
<binding name="listener" expression="listeners.logout"/>
</component>
<component id="username" type="Insert">
<binding name="value" expression="page.visit.member.username"/>
</component>
</component-specification>
Jim
--
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"Congratulations are in order for Tom Reid. He says he just found out
he is
the winner of the 2021 Psychic of the Year award." -- Seen on slashdot
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Life cycle and a mystery
Posted by Bryan Lewis <br...@maine.rr.com>.
I have a similar component and haven't seen a problem like this. As you
suggested, posting your files would help. I'm guessing it's something
in the java code. Here's mine, with the presentation stuff stripped out
for simplicity:
.html:
-----
<form jwcid="@Form" listener="ognl:listeners.formSubmit"/>
<span jwcid="@Conditional" condition="ognl:!loggedIn">
<td>
UserName <input jwcid="@TextField" value="ognl:login"/>
Password <input jwcid="@TextField" value="ognl:password"
hidden="true"/>
<a jwcid="loginSubmit"/> <!-- an ImageSubmit -->
</td>
</span>
<span jwcid="@Conditional" condition="ognl:loggedIn">
<td>
<span jwcid="@Insert"
value="ognl:page.visit.user.fullName"/>
<a jwcid="logoutSubmit"/> <!-- an ImageSubmit -->
</td>
</span>
</form>
The jwc file isn't pertinent in this case.
.java
-----
public boolean isLoggedIn()
{
// Check whether there's already a Visit for this user, without
// calling getPage().getVisit() which would automatically create
one.
Map visit = (Map) getPage().getEngine().getVisit();
if (visit == null) {
return false;
}
if (visit.get("user") == null) {
return false;
}
return true;
}
----- Original Message -----
From: "Jim Menard" <ji...@io.com>
To: "Tapestry users" <ta...@jakarta.apache.org>
Sent: Saturday, December 13, 2003 10:55 AM
Subject: Life cycle and a mystery
> After getting quite far in my app development, I now have to
understand
> a component's life cycle, if that's the correct term. I've started
> reading the Developer's Guide more closely.
>
> Here's my mystery: I have a log out component that contains a form, a
> "Log Out" LinkSubmit, and an "Insert" that displays the username. This
> component is inside another component that wraps the log out inside a
> Conditional that makes sure the user is logged in. After I log in, the
> log out component displays correctly. However, when I click on the
link
> to log out an exception is raised because the log out component tries
> to access the user name but the user object is now null.
>
> Why is the log out component and its Insert even being accessed? It's
> wrapped inside a Conditional that is false when the user is logged
out,
> so it should never try to access the user name.
>
> I can work around this problem by adding an additional Conditional
> around the username Insert itself, but this seems redundant. The log
> out component shouldn't be accessed at all because of the outer
> component's Conditional. Why do I need the same Conditional inside the
> log out component?
>
> Thank you for your help. I can post the .html and .jwc files if my
> explanation is too confusing.
>
> Jim
> --
> Jim Menard, jimm@io.com, http://www.io.com/~jimm/
> "Never anthropomorphize computers. They hate that." -- Ricdude on
> slashdot
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Life cycle and a mystery
Posted by Glen Stampoultzis <gs...@iinet.net.au>.
At 02:27 AM 15/12/2003, you wrote:
>On Dec 14, 2003, at 9:59 AM, Harish Krishnaswamy wrote:
>
>>You are right, you don't need the ognl: prefix in the .jwc binding
>>expression.
>>
>>You might want to try FormConditional in contrib. A lot of these problems
>>is because your render and rewind phases do not match.
>
>That's what I don't yet understand: render and rewind phases. My next task
>is to thoroughly understand the "Understanding the Request Cycle" chapter
>in the Developer's Guide.
It wouldn't hurt to run through the tapestry code with a debugger
too. I've been learning a lot that way.
Regards,
Glen Stampoultzis
gstamp@iinet.net.au
http://members.iinet.net.au/~gstamp/glen/
Re: Life cycle and a mystery
Posted by Jim Menard <ji...@io.com>.
On Dec 14, 2003, at 9:59 AM, Harish Krishnaswamy wrote:
> You are right, you don't need the ognl: prefix in the .jwc binding
> expression.
>
> You might want to try FormConditional in contrib. A lot of these
> problems is because your render and rewind phases do not match.
That's what I don't yet understand: render and rewind phases. My next
task is to thoroughly understand the "Understanding the Request Cycle"
chapter in the Developer's Guide.
Jim
--
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"Anyway, I heard that The Artist Formerly Known As Prince has now
renamed himself 'The Artist', making his full title 'The Artist,
Formerly
Known As The Artist Formerly Known As Prince, Formerly Known As
Prince'." -- Screwtape
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Life cycle and a mystery
Posted by Harish Krishnaswamy <hk...@comcast.net>.
You are right, you don't need the ognl: prefix in the .jwc binding expression.
You might want to try FormConditional in contrib. A lot of these problems is because your render and
rewind phases do not match.
-Harish
Jim Menard wrote:
> On Dec 14, 2003, at 9:20 AM, Howard M. Lewis Ship wrote:
>
>> Check the condition parameter of your Conditional.
>>
>> You may have omitted the "ognl:" prefix, and the Conditioal is
>> treating a non-empty string as true.
>
>
> I'll check that, but the Conditional is in the .jwc file and uses a
> binding. I thought I didn't need the "ognl:" prefix.
>
> <component id="ifLoggedIn" type="Conditional">
> <binding name="condition" expression="page.visit.loggedIn"/>
> </component>
>
>
> Jim
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Life cycle and a mystery
Posted by Jim Menard <ji...@io.com>.
On Dec 14, 2003, at 9:20 AM, Howard M. Lewis Ship wrote:
> Check the condition parameter of your Conditional.
>
> You may have omitted the "ognl:" prefix, and the Conditioal is
> treating a non-empty string as true.
I'll check that, but the Conditional is in the .jwc file and uses a
binding. I thought I didn't need the "ognl:" prefix.
<component id="ifLoggedIn" type="Conditional">
<binding name="condition" expression="page.visit.loggedIn"/>
</component>
Jim
--
Jim Menard, jimm@io.com, http://www.io.com/~jimm/
"COGITO, EGGO SUM." I think, therefore I am a waffle.
-- .sig of Mr. Ska on Slashdot.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
RE: Life cycle and a mystery
Posted by "Howard M. Lewis Ship" <hl...@comcast.net>.
Check the condition parameter of your Conditional.
You may have omitted the "ognl:" prefix, and the Conditioal is treating a non-empty string as true.
--
Howard M. Lewis Ship
Creator, Tapestry: Java Web Components
http://jakarta.apache.org/tapestry
http://jakarta.apache.org/commons/sandbox/hivemind/
http://javatapestry.blogspot.com
> -----Original Message-----
> From: Jim Menard [mailto:jimm@io.com]
> Sent: Saturday, December 13, 2003 10:55 AM
> To: Tapestry users
> Subject: Life cycle and a mystery
>
>
> After getting quite far in my app development, I now have to
> understand
> a component's life cycle, if that's the correct term. I've started
> reading the Developer's Guide more closely.
>
> Here's my mystery: I have a log out component that contains a form, a
> "Log Out" LinkSubmit, and an "Insert" that displays the
> username. This
> component is inside another component that wraps the log out inside a
> Conditional that makes sure the user is logged in. After I
> log in, the
> log out component displays correctly. However, when I click
> on the link
> to log out an exception is raised because the log out component tries
> to access the user name but the user object is now null.
>
> Why is the log out component and its Insert even being accessed? It's
> wrapped inside a Conditional that is false when the user is
> logged out,
> so it should never try to access the user name.
>
> I can work around this problem by adding an additional Conditional
> around the username Insert itself, but this seems redundant. The log
> out component shouldn't be accessed at all because of the outer
> component's Conditional. Why do I need the same Conditional
> inside the
> log out component?
>
> Thank you for your help. I can post the .html and .jwc files if my
> explanation is too confusing.
>
> Jim
> --
> Jim Menard, jimm@io.com, http://www.io.com/~jimm/
> "Never anthropomorphize computers. They hate that." -- Ricdude on
> slashdot
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org