primefaces Cancel button not navigating to previous page - jsf

I have a p:commandButton, which when I click on, I want it to take me to the previous page. This is the code I have used -
<p:commandButton id="cancel" value=" Cancel" action="cancel" ajax="false" process="#this"/>
However, when I click on Cancel, nothing happens. Please let me know how I can get my button to navigate to the previous page.

You can use javascript in the oncomplete event of the button.
oncomplete = "window.history.back();"

Related

How to add confirmation check for a button which is calling a remoteCommand

I have a situation in primefaces, where I have a button which on click calls a remote command through java script as a callback, this remote command is responsible to perform save action. I want to add confirmation to the Save button based on some controller value. So the expected output is on click if that value is true I want to show the confirmation dialog else I just want to do the normal save.
I am really new to primefaces. Any help would be highly appreciated.
<p:remoteCommand name="save" actionListener="#{controller.save()}" oncomplete="PF('statusDialog').hide()"/>
<p:button value="Save" styleClass="btn-primary btn-save" onclick="PF('statusDialog').show(); Modeler.saveBpmnToForm(save)" />
Whenever you trigger the remote command you could redirect the action to show the actual confirm dialog, then from there you can associate the action with the "confirm" button. The following logic is meant to show the dialog only if your boolean variable is true, otherwise you perform the save action without showing any dialog.
<p:remoteCommand name="save" actionListener="#{controller.status ?
controller.showDialog : controller.save}" oncomplete="PF('statusDialog').hide()"/>
Whenever this remoteCommand is triggered you'll show the following dialog using the bean:
<p:dialog id="confirmDialog" >
<p:button value="Confirm" styleClass="btn-primary btn-save"
onclick="PF('statusDialog').show()" action="#{controller.save}"/>
<p:button value="Cancel" styleClass="btn-primary btn-cancel"
onclick="PF('confirmDialog').hide()"/>
</p:dialog>
The "confirm" button will perform the actual logic, the "cancel" should only close the dialog but this is up to you.

p:commandButton click updates h:form unwantedly

<p:commandButton id="excelAccountLevelOneAccLvl1" ajax="false" icon = "fa fa-fw fa-download" >
<f:param name="accountLevelOneFormRequest" value="accountLevelOneFormRequest" />
<p:dataExporter type="xlsx" target="baselineOneTable"
fileName="#{exportToExcelPageBean.fileName}"
postProcessor="#{exportToExcelPageBean.postProcessXLS}" />
</p:commandButton>
On clicking this button, somehow the forms seems to update and it activates the Faces validation and asks me to fill enter the mandatory field values! I can't figure out why! There is not update parameter here at all!
update is for ajax requests only. You are using ajax="false" which means the commandButton activates a
full page request. That in turn means that the whole form in which the commandButton is included is
processed. If you want to avoid this put your commandButton in a separate form.

p:commandButton show other button after this button clicked

Hi I have a JSF "Register.xhtml" inside I have two Primefaces Command Buttons:
<p:commandButton id="registerButton"
action="#{registerController.register()}" rendered="#{!registerController.IsUserRegistered()}" />
<p:commandButton id="unregisterButton"
action="#{registerController.unregister()}" rendered="#{registerController.IsUserRegistered()}"/>
It works if I manually refresh the page.
I want a method to show the unregisterButtonand hiding the registerButton after I call the
registerController.register() function by clicking on the register Button.
You need to refresh the part of the page where the second button is after the click on the first button.
With Primefaces you can use PartialSubmit, http://www.primefaces.org/showcase/ui/ajax/partialSubmit.xhtml

JSF richfaces: update (rerender) element + close popup on click a4j:commandButton

I have a a4j:commandButton in my popup. On click I want to hide my popup and rerender some component.
<a4j:commandButton type="button" styleClass="left" value="#{bean.value}"
actionListener="#{bean.action}"
render="updComponent"
oncomplete="#{rich:component('popup')}.hide()"/>
In this case component is rerendered, but popup isn't hiding.
If I use rerender="updComponent" instead of render="updComponent", popup is hiding, but element isn't rerendered.
If I use instead of oncomplete="#{rich:component('popup')}.hide()" this:
<rich:componentControl target="deactivateIp" event="oncomplete" operation="hide"/>
popup isn't hiding, component isn't rerendering.
What I'm doing wrong and how to achieve what I want?
I've used onbegin instead of oncomplete and it works for me.
If I don't mistake, it's jsf bug: after render oncomplete event isn't firing.
<a4j:commandButton type="button" styleClass="left" value="#{bean.value}"
actionListener="#{bean.action}"
render="updComponent"
onbegin="#{rich:component('popup')}.hide()"/>
Maybe not the best solution, but I haven't found out any other.

Opening a Rich Modal Panel on Button Click

I m trying to open a rich modal panel with populated data on a button click
tried
<h:commandButton id="btn_search" value="#{text['button.add']}"
action="#{cartBean.search}"
oncomplete="#{rich:component('dlg_results')}.show()">
</h:commandButton>
and
<h:commandButton id="btn_search" value="#{text['button.add']}"
action="#{cartBean.search}" immediate="true">
<rich:componentControl for="dlg_results" attachTo="btn_search" operation="show" event="onclick"/>
</h:commandButton>
This code opens the model panel on button click but when response is sent back from the server the whole page gets refreshed
can some one suggest a way to handle this ???
Use <a4j:commandButton> instead of h:commandButton.
Thanks, this was helpful information.
I used showWhenRendered tag in rich:modalpanel to solve my problem. I added a variable in my bean and set its value to true on click of button if records are found.

Resources