h:link/h:button outcome methods automatically called during page load without any clicks

删除回忆录丶 提交于 2019-12-02 02:02:56
BalusC
<a href="#{bean.gotoMySrchie()}">           

<h:link ... outcome="#{bean.gotoMySearches()}">

They are called as value expressions because their return value needs to be printed in there during generating the HTML output during the JSF render response phase. Their return value is used as href in the resulting HTML output. Rightclick the page in webbrowser, do View Source and look at the value of the href attribute. If those methods returned String, you'll see exactly that string being printed there.

They are, on the contrary to what you expected, not called as method expressions during JSF invoke application phase as result of a postback. This is just a fundamental misunderstanding. To invoke actions during a postback, you need <h:commandXxx action>. This however fires a POST request, not a GET request, which may thus have many other consequences.

Clicking a plain link by default sends a GET request not a POST request. If you want to keep using GET, which is a good thing in this specific case, then you should be doing the database job in the @PostConstruct method of the backing bean associated with target page instead of during loading the page containing those links as you did there.

<h:link ... outcome="/searches">
    <h:graphicImage ... />
</h:link>
@Named
@RequestScoped // Or @ViewScoped
public class SearchesBean {

    @PostConstruct
    public void init() {
        // Here.
    }

    // ...
}

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!