How to use both Navigation Rule and f:ajax

强颜欢笑 提交于 2019-12-22 11:01:41

问题


Here's my scenario: I'd like to update a page via Ajax in some cases, in other cases, execute a navigation rule. My use case is a login form. I'd like them to receive an error message via ajax if their uname/password fails, but navigate to a new page if it succeeds.

Has anyone done this using JSF2.0 f:ajax apis? I'm not really interested in solutions that go outside standard facelets, jsf2.0, etc.


回答1:


It's not different from when doing it without ajax. Just return the next view ID as String the usual way via <h:commandXxx action> (and thus not <f:ajax listener>).

So, just

<h:commandButton value="Login" action="#{bean.login}">
    <f:ajax execute="@form" render="@form" />
</h:commandButton>

with

public String login() {
    // ...

    return "nextpage";
}

will work as good as without <f:ajax>. It'll just go to nextpage.xhtml.

See also:

  • Differences between action and actionListener
  • JSF f:ajax listener vs commandButton action


来源:https://stackoverflow.com/questions/9123625/how-to-use-both-navigation-rule-and-fajax

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