-
1. Re: Visits counter
yk Aug 5, 2009 4:31 PM (in response to mike82)hi,
take a look at the seam documentation to see how to create an application scoped componenent.
you will have to use an annotation like this :@Scope(APPLICATION) @Startup public class VisitCounterComponent{ }
by the way you could also use the interceptors: My Link
-
2. Re: Visits counter
mike82 Aug 7, 2009 11:38 AM (in response to mike82)but the problem is not creating of app-scoped component but accessing it in the filter. When I try in session bean org.jboss.seam.contexts.Contexts.getApplicationContext().get(MyClass.class) I can access my component, but in filter org.jboss.seam.contexts.Contexts.getApplicationContext() returns null.
That's why I ask, how to make workaround for this problem, with this interceptors thing? Or I've read also about context-filters, but they are only defined for servlets and I have no idea how could I use it in this situation.
-
3. Re: Visits counter
lvdberg Aug 7, 2009 11:45 AM (in response to mike82)is it not easier to log data in a specific session-scoped bean which will be auto-created on creating the session, or maybe simpler adding an event everytime a specific page is viewed. These events can be observerd through @Observer) and that
observer bean
can be used for logging. -
4. Re: Visits counter
mike82 Aug 7, 2009 12:05 PM (in response to mike82)could be. but what I am concerned about is situation when I have big traffic on site. That's why I wanted one common place in memory to record visits/pages/referers and when fx list grows to 50 elements, then persist all of them to database.
In your solution, which is interesting, I'm afraid I have to save to db for each user separately. Perhaps it could somehow expanded?
-
5. Re: Visits counter
lvdberg Aug 7, 2009 12:17 PM (in response to mike82)Majkel,
Sending an event to a specific bean doesnt mean you have to save it directly. You could save it in memory and every time you exceed a specific amount of events you save it to disk. I would definiely increase the number of records and add a time limit of an hour (suppose its sunday morning and you won't have a lot of visitors) You can add whatever kind of Object to the parameterList of an event so you can do whatever you want with the observer which basically provides an component independent way of inetraction between independent beans.
The most important advantages I see is that you won't interfere with the Seam-cycle with an additional Filter and you can stick to a 100% Seam solution.
I've made a number of applications with additional servlets/beans etc. but i am more-and-more trying to reduce this to a minimum at the moment because of maintenance.
Leo
-
6. Re: Visits counter
mike82 Aug 7, 2009 2:32 PM (in response to mike82)I got your idea and I've read some on this matter. I think I will go this way, but it has one weak point (hasn't it?). I have to place code for raising event on specific page. For example home.seam, in some code reading data for page. If I'd like to log all the pages I have to do it with all pages? Or fx in code for common page template? But then I have to check if it's unique visit. Sorry if it's dumb question, but I've just started with Seam and actually had no time to go deep inside it.
-
7. Re: Visits counter
lvdberg Aug 7, 2009 3:22 PM (in response to mike82)Just create a specific sessions-scoped bean or add it as a super function to the page-bean you want monitored (For instance if you want to know that some page has been seen, you could add it to a create method of the related bean. This will off-course only work if you reference the bean in the page.
-
8. Re: Visits counter
mike82 Aug 7, 2009 3:28 PM (in response to mike82)thanks for help Leo, I try to implement it now
-
9. Re: Visits counter
brandonsimpson Aug 7, 2009 4:58 PM (in response to mike82)I haven't tried it...but if you created a page-scoped (or request-scoped) bean and annotated it with @Startup, wouldn't that cause it to be automatically created on every page without having to actually use it explicitly? Worth a shot!