问题
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