Cancel navigation button in JSF

I have a cancel button on a page. But this page can be opened from different places. I mean the parent page might be different.

Now, by clicking on the cancel button, I need to go back to the page where I came from - how history.back()

.

How can we implement this in JSF?

Can someone please guide me?

And this one history.back()

doesn't work directly.

<h:commandButton type="button" id="cancel" image="#{sessionScope.sessionObject.graphicImageFolderName}cancel_btn.gif" accesskey="#{bundle.oscer_command_cancel_accesskey}" value="Cancel" action="#{templatePrescriptionMaintenanceBackingBean.goBack}" />

      

In case history.back()

I am doing the same button as ..

<h:commandButton type="button" id="cancel" image="#{sessionScope.sessionObject.graphicImageFolderName}cancel_btn.gif" accesskey="#{bundle.oscer_command_cancel_accesskey}" value="Cancel" onclick="javascript: history.back();"/>

      

Is there something wrong in both cases?

+4


source to share


2 answers


Try

<h:commandLink onclick="history.go(-1); return false;">

      

or



<h:commandButton onclick="history.back(); return false;">

      

works for you?

+5


source


Get the default navigation handler via Application.getNavigationHandler . Wrap it in proxy reflection and set the proxy as the new default navigation handler via Application.setNavigationHandler . In the proxy call handler, you can track all navigation events with their results and build your history from this. Then use that story to navigate the Cancel button back to your story.



+1


source







All Articles