Reputation: 1319
Following line should save a new item and redirect to another page. So far, it saves correctly, but it doesn´t redirect. No errors or warnings.
<p:commandButton id="savebutton" ajax="false" value="#{msg['addCategory.save']}" actionListener="#{addCategoryController.doSave()}" />
Code behind:
public String doSave(){
categoryAddEvent.fire(categoryProducer.getSelectedCategory());
return Pages.LIST_CATEGORIES;
}
As I said, the first line executes correctly, the second one doesn´t seem to do anything. Any ideas what I could be doing wrong?
Upvotes: 4
Views: 18169
Reputation: 320
You can do it in two ways:
Calling an action, with the commandButton component set as ajax false, and the bean method returning a String (as you already have).
xhtml page:
<p:commandButton id="savebutton" ajax="false" value="#{msg['addCategory.save']}" action="#{addCategoryController.doSave()}" />
Calling an actionListener, with the commandButton component set as ajax true, with the bean method not returning value, but instead performing itself the redirection to the desired page.
xhtml page:
<p:commandButton id="savebutton" ajax="true" value="#{msg['addCategory.save']}" actionListener="#{addCategoryController.doSave()}" />
java bean:
public void doSave(){
categoryAddEvent.fire(categoryProducer.getSelectedCategory());
FacesContext.getCurrentInstance().getExternalContext().redirect(Pages.LIST_CATEGORIES);
}
Upvotes: 14