aspose file tools*
The moose likes JSF and the fly likes Hit Counter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Hit Counter" Watch "Hit Counter" New topic

Hit Counter

Christopher Sharp
Ranch Hand

Joined: Dec 12, 2007
Posts: 155
This is my first posting on this board, and I'm new to JSF and Glassfish, as well as server-side programming in Java in general.

I am using Java Server Faces with Glassfish, and I would be very
grateful to know how to implement hit counters. I am putting together
a website with three main pages, the first is basically an index page,
then depending on which of two links are followed, you are taken to
one of two pages containing large forms which have to be submitted. I
would like to put a hit counter on all three pages, and possibly
separate counters that record how many times the "submit" button has
been clicked.

Rather than having three separate beans for each counter, it would
make sense to have one bean that reads and updates one of three very
small files that store the counter for the particular page. When the
page loads, how do I tell the counter which file to read and update?
Once I have the value from the counter, then it is just a matter of
using the hutputText tag, but of course that tag has to be
rendered after it has the value?

After the "submit" button is clicked, a quite separate counter can be
updated, which should be much easier. In the web page I have a JavaScript function that on page load passes a string to:

h:inputHidden id="update" value="#{user.counter}"

in a form using the DOM, then immediately I have the line:

hutputText id="newvalue" value="#{user.counter}"

that is supposed to return the count from the counter file.

The code for the bean is:

Depending on which of the three (or in general more) pages I have
placed the counter in, I want to call up the file that holds the count for
that page and update it. What happens at the moment is that the bean tries to display a number before it has got the file, so it fails.

It's a bad idea to pass the filename directly to the bean, and I could instead have the filenames stored in the bean, but I would still need
to specify which file I want to access for a particular page. I could of
course write separate logic for each page that are identical, except for
filename, but there must be a better way. Incidentally, I tried to post the HTML code, but that wasn't possible.

I would be most grateful for some help on this, which may involve configuring the faces-config.xml and/or the web.xml files in a special way, for which I'm having problems finding documentation.

Christopher Sharp
I agree. Here's the link:
subject: Hit Counter