简体   繁体   English

JSF如何在页面刷新时停止@ManagedBean类的自动方法调用

[英]How can be stopped automatic method call from @ManagedBean class at page refresh, JSF

In my XHTML page I'm calling a method from my @ManagedBean class. 在我的XHTML页面中,我从@ManagedBean类中调用一个方法。 The method should be executed only when I click the link which to is linked the method: 仅当我单击要链接到该方法的链接时,才应执行该方法:

  <h:link value="Continue Reading &raquo;" 
       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. 我也尝试了h:commandLink,但是结果是一样的。 Do you have an idea what I need to change, or what is wrong? 您是否知道我需要更改或有什么问题? The @ManagedBean class is application scoped. @ManagedBean类是应用程序范围的。 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);
    }
}

onClick is a handler for JavaScript in the webbrowser! onClick是Web浏览器中JavaScript的处理程序! The Method you call is Java and executed on the server! 您调用的方法是Java,并在服务器上执行!

Java renders the Website before the website is sent to the webbrowser, in this phase is the method is invoked. 在将网站发送到Web浏览器之前,Java会渲染网站,此阶段将调用该方法。 After the sending to the webbrowser the javascript can be executed, this is a second phase. 发送到Web浏览器后,可以执行javascript,这是第二阶段。 You simply need a new request to the server for executing java-methods. 您只需要向服务器发出新请求即可执行java方法。 I prefer to use a4j:jsFunction . 我更喜欢使用a4j:jsFunction

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM