0 Replies Latest reply on May 6, 2011 11:31 AM by Martin Dubuc

    Detecting change of view composition

    Martin Dubuc Newbie

      I have migrated my application to JSF 2.0 and RichFaces 4.0.0.Final. When I used JSF 1.2, I had some JavaScript code that executed when the user left a page using this kind of construct:

       

      window.onbeforeunload = chkDirty;

       

      function chkDirty(evt) {

          if (isDirty())

              return "Changes to this page haven't been save. Are you sure you want to exit?";

      }

       

      In the new application, I am using facelets templating. My page has a template that points to a header view, a panel menu side view and the content view, which is a ui:compostion. I use a rich:panelMenu to select the view to present in the content composition view. For instance, if I click on menu item abc, the application loads abc.xhtml which points back to a template with the header and panel menu side view and the appropriate abc content. One issue I find now is that when clicking on the abc item, the page is updated to present the abc view, but the URL does not change. When I select another item (say item def), the content is changed to def, but it looks as though the page doesn't unload because my chkDirty routine does not get called. If I replace the URL in my browser with def.xhtml to load def content while I am on page abc.xhtml, then the page unloads and the chkDirty function gets called.

       

      I am wondering how I can achieve similar functionality as page unloading when using JSF 2.0/RichFaces 4 (with rich:panelMenu). In the rich:panelMenu, I am using itemMode ajax and groupMode ajax. I tried to set both to server, but then, when I clicked the menu item, the content composition view does not get updated.

       

      Martin