You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2009/02/10 16:04:16 UTC

T5: keeping track of correct count during a session

Hi,

I'm not sure if this is related to T5, here is what I'm doing:

I need to keep track of how many time a certain record is being viewed, here
is what I do:

@CommitAfter
   void setupRender() {
       this.getCurrentDoc().incView();
   }

This works, but if user clicks twice, it is counted twice as well, I'd like
to count only once, maybe in the same session. any way to achieve this?

Thanks,

Angelo
-- 
View this message in context: http://www.nabble.com/T5%3A-keeping-track-of-correct-count-during-a-session-tp21935539p21935539.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: keeping track of correct count during a session

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
hi angelo,

this is a classical multiple click problem. you can solve it
on the client-side by deactivating any link after it was clicked
(lots of javascript involved) or on the server-side by generating 
some unique tokens that are checked on every request.

a solution that works really fine for my applications involves 
contributing a Dispatcher that creates a unique token and saves 
it into the cookie using the Cookies service - for any request. 
the dispatcher will also check if the set token (if set) is still valid 
and 
invalidate it. if a link is clicked multiple times the request will send 
the same cookie to the server. the first request will be processed as 
expected. any subsequent request will be redirected to an error page 
because the token has been invalidated.

of course it only works if cookies are enabled


g,
kris






Angelo Chen <an...@yahoo.com.hk> 
10.02.2009 16:04
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
users@tapestry.apache.org
Kopie

Thema
T5: keeping track of correct count during a session








Hi,

I'm not sure if this is related to T5, here is what I'm doing:

I need to keep track of how many time a certain record is being viewed, 
here
is what I do:

@CommitAfter
   void setupRender() {
       this.getCurrentDoc().incView();
   }

This works, but if user clicks twice, it is counted twice as well, I'd 
like
to count only once, maybe in the same session. any way to achieve this?

Thanks,

Angelo
-- 
View this message in context: 
http://www.nabble.com/T5%3A-keeping-track-of-correct-count-during-a-session-tp21935539p21935539.html

Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org



Re: T5: keeping track of correct count during a session

Posted by Peter Stavrinides <P....@albourne.com>.
Hi Angelo

I did something similar, but for my purposes I didn't need anything fancy, this is what I did:

// A flag to check if the number of views field has been updated
@Persist("flash")
private boolean _viewsUpdated;

void onActivate(int topicId){
...

// number of topic views is incremented for a given topic
		int views = 0;
		if (_topic.getViews() != null)
			views = _topic.getViews();

		//a check required to prevent duplicate writes
		if (!_viewsUpdated) {
			_topic.setViews(views + 1);
			_topic.update();
			_viewsUpdated = true;
		}
}

You can easily adapt this for your event link, its the same principle in essence, you can also use @Persist proper if you consider a view as once per session, I considered a view as once per page load, thats why I used flash persistence instead.


Cheers,
Peter



----- Original Message -----
From: "Angelo Chen" <an...@yahoo.com.hk>
To: users@tapestry.apache.org
Sent: Tuesday, 10 February, 2009 17:04:16 GMT +02:00 Athens, Beirut, Bucharest, Istanbul
Subject: T5: keeping track of correct count during a session


Hi,

I'm not sure if this is related to T5, here is what I'm doing:

I need to keep track of how many time a certain record is being viewed, here
is what I do:

@CommitAfter
   void setupRender() {
       this.getCurrentDoc().incView();
   }

This works, but if user clicks twice, it is counted twice as well, I'd like
to count only once, maybe in the same session. any way to achieve this?

Thanks,

Angelo
-- 
View this message in context: http://www.nabble.com/T5%3A-keeping-track-of-correct-count-during-a-session-tp21935539p21935539.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org