In the previous chapter, we saw that performing business logic and redirecting a user to a different web page can be performed by adding a commandButton
to a web page. The action
property of a commandButton
specifies the business method to be executed, and this method is then responsible for routing the user to a web page. If we want to route the user back to the same page they were viewing before clicking on the actionButton
, the business method simply returns an empty string, as shown in the following code snippet.
<h:commandButton action="#{manager.run}" value="Run" /> @Name("manager") … public String run() { return ""; }
This is the simplest possible case—returning the user to the same point at which they started. Although this type of page routing can be very useful, it is highly limited. It is much more useful to redirect a user to a different page after performing some business action.