You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Steven Schermerhorn <ge...@gmail.com> on 2005/04/30 18:01:47 UTC
Visit Object
Hello, I need a little bit of direction with regards to using the Visit
object appropriately.
I've created a simple sign-in form. When a user logs in, it stores an
instance of 'User' class inside the visit object.
My problem is that it seems like Tapestry is associating the visit
object with the page engine rather than the session.
From what I can tell, Tapestry puts more than one copy of a page in
memory, and then uses these to serve multiple clients. (Is that right?)
After I sign in, I get the message showing that I'm signed in. When I
pull up another browser (even from another host), I get the same message
saying that the user is signed in. The inspector even shows the User
class in the Visit object. If I keep refreshing the page on the second
browser, it will switch between the sign-in form, and the 'you are
signed-in' screen. This leads me to think that the Visit object is being
stored with the page rather than the session.
The sign-in form is in a component. If the user isn't signed in, it
shows the sign-in form, otherwise, it shows the "you are signed in"
message. This is how I am populating the form.
---- from the signin.java component class file -------
public void prepareForRender(IRequestCycle cycle)
{
super.prepareForRender(cycle);
Visit visit = Visit.getVisit(cycle);
if(visit.isLoggedIn())
{
setLoggedIn(true);
setNickname(visit.getUser().getNickName());
return;
}
setNotLoggedIn(true);
}
---------------------------------------------------
This is how I am getting the Visit object
--------------------Visit.java -------------------
public class Visit implements Serializable
{
private static final long serialVersionUID = 3258134648079857714L;
private User user = null;
public boolean isLoggedIn() { return (user != null); }
public User getUser() { return user; }
public void setUser(User user) { this.user = user; }
public static Visit getVisit(IRequestCycle cycle) {
Visit visit = (Visit)cycle.getEngine().getVisit();
if(visit == null) {
visit = new Visit();
cycle.getEngine().setVisit(visit);
}
return visit;
}
}
---------------------------------------
Thanks!
-Steven
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
Re: Visit Object
Posted by Steven Schermerhorn <ge...@gmail.com>.
Thanks! I think that was the problem I was having!
sastan wrote:
>> public static Visit getVisit(IRequestCycle cycle) {
>> Visit visit = (Visit)cycle.getEngine().getVisit();
>> if(visit == null) {
>> visit = new Visit();
>> cycle.getEngine().setVisit(visit);
>> }
>> return visit;
>> }
>>
>>
>I don't think you need this. You can access the visit object from within
>the component with getPage().getVisit(). The visit object will
>automaticly created on the first access.
>
>sastan
>
>
>
>---------------------------------------------------------------------
>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: Visit Object
Posted by sastan <sa...@e-d-o-t.com>.
> public static Visit getVisit(IRequestCycle cycle) {
> Visit visit = (Visit)cycle.getEngine().getVisit();
> if(visit == null) {
> visit = new Visit();
> cycle.getEngine().setVisit(visit);
> }
> return visit;
> }
I don't think you need this. You can access the visit object from within
the component with getPage().getVisit(). The visit object will
automaticly created on the first access.
sastan
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org