问题
I'm using PrimeFaces and have a Save button, basically a maintenanceTask is sent to my page, I edit it within here, then press Save and it should be saved to the database and then redirected to the original page. I have a working Save method, but can't seem to get both the navigation and method to fire off.
<p:commandButton value="#{message.commonButtonSave}"
title="#{message.commonSaveTooltip}"
rendered="#{maintenanceTaskEnquiryBean.screenMode == 'editTasks'}"
disabled="#{maintenanceTaskEnquiryBean.outstandingEditCount != 0}"
action="/definemaintenance/MaintenanceTasksActivity"
actionListener="#{maintenanceTaskEnquiryBean.save}" >
</p:commandButton>
There is what I have at the minute, but I have tried many different variations on this including p:button and p:commandButton, listener/actionListener, target/outcome/action etc...
Any suggestions please?
Thanks.
回答1:
If you want to perform action, and navigate afterwards, use action
attribute and return the navigation rule as a result.
<p:commandButton value="#{message.commonButtonSave}"
title="#{message.commonSaveTooltip}"
rendered="#{maintenanceTaskEnquiryBean.screenMode == 'editTasks'}"
disabled="#{maintenanceTaskEnquiryBean.outstandingEditCount != 0}"
action="#{maintenanceTaskEnquiryBean.save}">
</p:commandButton>
The save()
method would look something like this
public String save() {
// perform whatever you need to, and then
return "<some navigataion rule>";
}
The return string should open the desired page /definemaintenance/MaintenanceTasksActivity
.
来源:https://stackoverflow.com/questions/26647909/pcommandbutton-or-pbutton-with-actionlistener-and-outcome