3 Replies Latest reply on Apr 7, 2010 11:07 AM by saini.sushant

    How to check for dirty form in Richfaces?

    saini.sushant

      I have a requirement, if the user has changed any data on page and he is trying to click some link, I should be showing an alert message stating that if they move away they will loose the changes they have made.

       

      Is there any standard approach to this problem using Richfaces or has any one done something like this in past which I can reuse?

        • 1. Re: How to check for dirty form in Richfaces?
          m.a.g

          I use rich:modalPanel for editing, so user can't click any links until he/she press "Save" or "Cancel" button placed on modal panel. If user clicks "Cancel" you can check if some fields have been changed and show confirmation.

          1) You can use hidden inputs or some javascript to remember initial values of inputs, then compare initial to current values on "Cancel" to make decision if confirmation is required.

          2) The other way is just track "onchange" event and show confirmation on "Cancel" if "onchange" has been called at least once.

          • 2. Re: How to check for dirty form in Richfaces?
            ilya_shaikovsky

            no ready-to-use solution. you will have to create some custom one or use some plugins like http://github.com/acvwilson/dirty_form

            • 3. Re: How to check for dirty form in Richfaces?
              saini.sushant

              Hi All,

              After I posted my query here on Richfaces forum I did google to see if there is available library and I found what you suggested http://github.com/acvwilson/dirty_form. In fact this was only one available and just like Richfaces, it uses JQuery. It was easy and good enough but I had to customize it h:commandLinks.

               

              Getting this library working for normal hrefs was very very easy and covinient but I faced issues with h:commandLink as JSF uses onclick method to actually fire the event rather then href. When user clicks on the h:commandlink, click event is first processed by onclick funtion from JSF and then by the event Listerner created by this library. So no matter what you do in the library specific method you will not be able to stop the page from submission

               

              What that means is if you change anythig on the page and click on h:commandLink , library will open a confirmation box with 2 button Ok and cancel.

              Even if you click cancel button page will get submitted. This is more of a issues between this library and JSF rather then Libary and Richfaces. After spending like 2 days I got this working for my application which is using Richfaces 3.3.1. Other then this issue, this looks like a very solution.

               

              I am sure there are lots of applications which will need this feature or won't mind it if Richfaces provided as a part of main JARS and building a standad solution with this library as base would be very easy for us. I have attached here the modified JS file, my layout page and actual page where this is used. This surely can be a boosting point for us as Richfaces family in the market.

               

               

              Please feel free to contacts me if you need any further input on this topic.