p:commandButton or p:button with actionListener and outcome?

北慕城南 提交于 2019-12-13 05:01:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!