3 Replies Latest reply on Jan 6, 2011 11:39 PM by muralib12

    Problem with rich:ajaxValidator inside rich:modalPanel

    artemk

      Hello everybody,

       

      I have a weird problem when using rich:ajaxValidator component. Here is the setup:

      - A page contains an output text bound to an action bean value, along with the "Edit" button

      - When edit button is pressed, rich:modalPanel appears with an input to edit this value. The input is validated with rich:ajaxValidator in onblur event.

      - The modal panel has two aj4:commandButtons, "Update" and "Cancel". Cancel closes the modal panel without applying values, Update submits the form, reRenders the output text behind modal panel and closes the modal panel.

       

      The problem I experience is when I open the modal panel, make modifications in the input and allow them to be validated by rich:ajaxValidator but then press Cancel. When I reopen the modal panel, instead of having the value in the action bean, I have the value that I previously entered. This happens because when rich:ajaxValidator was invoked, apply request values phase was executed and input component value was updated with what I entered prior to cancelling the modal panel. So now, even when I reRender the whole modal panel when "Edit" button is pressed, the input uses the value stored in the component, instead of using action bean value even though update model values phase was never executed.

       

      I'm not sure if this is an expected behaviour for rich:ajaxValidator. It seems to me that rich:ajaxValidator should rollback the value change in the component independently of whether validation fails or not. However, if it is the expected behaviour, is there any walkaround for this issue for my particular case?

       

      Thank you

        • 1. Re: Problem with rich:ajaxValidator inside rich:modalPanel
          artemk

          In case anybody is wondering, I did eventually come up with a "hack"-solution. I created a subclass of HtmlAjaxValidator where I reset the submitted value of the parent input:

           

          public class MyAjaxValidator extends HtmlAjaxValidator {
              @Override
              public void broadcast(FacesEvent event) throws AbortProcessingException {
                  super.broadcast(event);
                  if (event.getComponent() == this) {
                      if (event instanceof ValidationEvent) {
                          // Reset input to original value
                          UIInput parent = (UIInput) getParent();
                          parent.resetValue();
                      }
                  }
              }
          }
          

           

          Then, I set my component as the default component for component type org.richfaces.AjaxValidator in faces-config.xml:

           

          <component>
              <component-type>org.richfaces.AjaxValidator</component-type>
              <component-class>mypackage.MyAjaxValidator</component-class>
          </component>
          
          • 2. Re: Problem with rich:ajaxValidator inside rich:modalPanel
            muralib12

            Thanks for Your solution... It helped me a lot.

            • 3. Re: Problem with rich:ajaxValidator inside rich:modalPanel
              muralib12

              Hi Artem,

               

              am facing the same problem with rich:calender too. if possible please test it and provide solution.

              Thanks in advance.