This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Hit Counter

Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 h:outputText 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:

h:outputText 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
rubbery bacon. rubbery tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic