以下行应保存新项目并重定向到另一个页面。到目前为止,它保存正确,但没有重定向。没有错误或警告。
<p:commandButton id="savebutton" ajax="false" value="#{msg['addCategory.save']}" actionListener="#{addCategoryController.doSave()}" />
背后代码:
public String doSave(){
categoryAddEvent.fire(categoryProducer.getSelectedCategory());
return Pages.LIST_CATEGORIES;
}
正如我所说,第一行正确执行,第二行似乎没有执行任何操作。有什么想法我可能做错了什么吗?
您可以通过两种方式完成此操作:
调用一个操作,将 commandButton 组件设置为 ajax false,并且 bean 方法返回一个 String(正如您已经拥有的那样)。
xhtml页面:
<p:commandButton id="savebutton" ajax="false" value="#{msg['addCategory.save']}" action="#{addCategoryController.doSave()}" />
调用 actionListener,将 commandButton 组件设置为 ajax true,bean 方法不返回值,而是自行重定向到所需页面。
xhtml页面:
<p:commandButton id="savebutton" ajax="true" value="#{msg['addCategory.save']}" actionListener="#{addCategoryController.doSave()}" />
爪哇豆:
public void doSave(){
categoryAddEvent.fire(categoryProducer.getSelectedCategory());
FacesContext.getCurrentInstance().getExternalContext().redirect(Pages.LIST_CATEGORIES);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)