In my XHTML page I'm calling a method from my @ManagedBean class. The method should be executed only when I click the link which to is linked the method:
<h:link value="Continue Reading »"
outcome="contracts/resources/data/imag2_facebook.html"
onclick="#{sessionFilter.incForLink2('contracts/resources/imagini/facebook.jpg','Facebook down? Current problems and status', 'contracts/resources/imagini/facebook.jpg')}" />
It's weird why the method is executed at every page refresh without clicking on the link. I want the method to execute only when I click on the link. I have also tried with h:commandLink but the results are the same. Do you have an idea what I need to change, or what is wrong? The @ManagedBean class is application scoped. The method I call is the following:
public void incForLink2(String link, String title, String imgAllLink) {
Article article = links.get(link);
if (article != null) {
Integer pageHits = article.getPageHits();
article.setPageHits(pageHits + 1);
System.out.println(link + " = " + pageHits);
} else {
Article article1 = new Article(1, title, link, imgAllLink);
links.put(link, article1);
}
}