13 Replies Latest reply on Nov 24, 2010 11:00 AM by Ilya Shaikovsky

    modalPanel strange behaviour when validating

    Benny Malev Newbie

      Hello.

      I have,

      Java version: jdk1.6.0_21

      JSF version: 1.2

      Richfaces version: 3.3.3.Final

      My problem is as follows:

      I have a page which contains a form with a list of entities(beans), using rich:rich:dataTable.

      Also, there is a rich:modalPanel which is opened when an entity is chosen from the table, and lets the user edit

      this entity.

      The fields in the modal panel are validated with required="true", and one of them with a custom validator.

      If a validation exception occurs on any of the fields when the "save" button is pressed, a message is shown

      on the panel. In that case i click on the "Cancel" button to return to the list of entities.

      Now, here comes the problem:

      After a validation exception, whatever entity i choose, the modalPanel is opened, but only the values that

      failed the validation are fetched from the corresponding bean. The values that passed the validation are not

      being fetched, and instead - they are kept from the first validation that had the validation exception.

      Never mind how many times i choose another entity this behavior continues. Untill i enter values that

      pass the validation, and thus the entity is saved.

      Needless to say, i rerender the modalPanel when the buttons are clicked and when an entity is chosen from

      the list.

      I spent very long time trying to figure this out but without success, and will appreciate very much some help.

       

      Thanks in advance.
        • 1. Re: modalPanel strange behaviour when validating
          Ilya Shaikovsky Master
          1 of 1 people found this helpful
          • 2. Re: modalPanel strange behaviour when validating
            Benny Malev Newbie

            Thanks Ilya but that didn't work:

            The a4j:region solution skips the validation.

            The binding solution ignores a4j:keepAlive which I also need.

            The example you gave me a link to doesn't fit me, because they don't use a validator, but make "validation" in the store method when the store button is clicked. (I want to show a validation message next to a specific component and not a global message).

            • 3. Re: modalPanel strange behaviour when validating
              Benny Malev Newbie

              Eventually i decided no to use JSF validation, but did my own checking when the "save" button is pressed, and eluded the problem.

              It's weird that you can't do a proper validation when staying in the same page (and having a table of choices).

              • 4. Re: modalPanel strange behaviour when validating
                Ilya Shaikovsky Master
                The a4j:region solution skips the validation.

                Not sure get the problem. region at demo used only around the edit control and not affects modal panel validation.

                The example you gave me a link to doesn't fit me, because they don't use a validator, but make "validation" in the store method when the store button is clicked. (I want to show a validation message next to a specific component and not a global message).

                At first store method contains no validation at all.

                     public void store() {
                          allCars.set(currentRow, currentItem);
                          keys.clear();
                          keys.add(currentRow);
                     }
                

                just standard JSF validators makes work. and any custom could be added.

                 

                And global message could be replaced with local to component without problems.

                • 5. Re: modalPanel strange behaviour when validating
                  Benny Malev Newbie

                  Where's the standard JSF validation in the example code?

                  Do you mean when there's a type mismatch and an exception is being thrown?

                   

                  <rich:modalPanel id="editPanel" autosized="true" width="450">
                          <f:facet name="header">
                              <h:outputText value="Edit Current Car" />
                          </f:facet>
                          <f:facet name="controls">
                              <h:panelGroup>
                                  <h:graphicImage value="/images/modal/close.png" id="hidelink"
                                      styleClass="hidelink" />
                                  <rich:componentControl for="editPanel" attachTo="hidelink"
                                      operation="hide" event="onclick" />
                              </h:panelGroup>
                          </f:facet>
                          <h:form>
                              <rich:messages style="color:red;"></rich:messages>
                              <h:panelGrid columns="1">
                                  <a4j:outputPanel ajaxRendered="true">
                                      <h:panelGrid columns="2">
                                          <h:outputText value="Make" />
                                          <h:inputText value="#{dataTableScrollerBean.currentItem.make}" />
                                          <h:outputText value="Model" />
                                          <h:inputText value="#{dataTableScrollerBean.currentItem.model}" />
                                          <h:outputText value="Price" />
                                          <h:inputText value="#{dataTableScrollerBean.currentItem.price}"
                                              label="Price" immediate="true" />
                                      </h:panelGrid>
                                      <rich:message showSummary="true" showDetail="false" for="price" />
                                  </a4j:outputPanel>
                                  <a4j:commandButton value="Store"
                                      action="#{dataTableScrollerBean.store}"
                                      reRender="make, model, price"
                                      oncomplete="if (#{facesContext.maximumSeverity==null}) #{rich:component('editPanel')}.hide();" />
                              </h:panelGrid>
                          </h:form>
                      </rich:modalPanel>

                   

                  Ilya Shaikovsky wrote:

                   

                  The a4j:region solution skips the validation.

                  Not sure get the problem. region at demo used only around the edit control and not affects modal panel validation.

                  The region i'm talking about is from the example you gave me a link to:

                  <h:outputText value="Enter credit card number:"/>
                  <h:inputText value="#{data.creditCard}"/>
                  <h:outputText value="Or use your pre-defined credit card:"/>
                  <a4j:region>
                  <a4j:commandLink immediate="true" action="#{data.useMyCreditCard}" reRender="..." value="#{data.myCreditCardName}"/>
                  </a4j:region>
                  <h:outputText value="Your entered credit card number:"/>
                  <h:outputText value="#{data.creditCard}" styleClass="output"/>

                   

                  and this skips the validation.

                  • 6. Re: modalPanel strange behaviour when validating
                    Ilya Shaikovsky Master

                    1) JSF tries to convert the price to numerical value and f failed - adds message

                    2) sorry main sample which I wanted to show - "working sample" it uses the similar scenario - modal for  editing.

                    • 7. Re: modalPanel strange behaviour when validating
                      Benny Malev Newbie

                      The thing is when in the same scenario i add my own validator or even required="true" i get the problem i mentioned above.

                      • 8. Re: modalPanel strange behaviour when validating
                        Ilya Shaikovsky Master

                        so I'm proposing to check our sources and see where the changes which affects that behavior.

                        1 of 1 people found this helpful
                        • 9. Re: modalPanel strange behaviour when validating
                          Benny Malev Newbie

                          OK, i did just that, and found out that you need to mark immediate="true" on each component that is being validated, and then it works!

                          BUT!

                          If on the demo project i put immediate="true" on another input, i.e.

                          <h:inputText value="#{dataTableScrollerBean.currentItem.model}" immediate="true"/>

                           

                          what i get is that if a validation doesn't pass and i press on the X button of the modelPanel and choose another row from the table,

                          all fields are being refreshed with correct data EXCEPT the second field (i.e. the above field) that i marked with immediate="true".

                          This happens to all additional fields marked with immediate="true".

                          And this i checked on the sources of the demo in the link you gave me above!

                          Please check this, to see i'm correct.

                          • 10. Re: modalPanel strange behaviour when validating
                            Benny Malev Newbie

                            Any suggestions for solution?

                            • 11. Re: modalPanel strange behaviour when validating
                              Ilya Shaikovsky Master

                              doh.. that will not works with more than one input.. seems weird workaround at sample and need to remove when will migrate to 4.x. if at least one new component value will be applyed before validation fail - it will not be updated on next show. So seems the only complete solution at blog to which I already pointed you http://livedemo.exadel.com/richfaces-local-value-demo/ - demo from that blog. with cleaning the value on UIComponent instance.

                              • 12. Re: modalPanel strange behaviour when validating
                                Benny Malev Newbie

                                Several problems with this solution:

                                First - what if i have 20 inputs? Go and clean all 20 UIComponents?

                                Second - for some reason, when i bind an input to the bean, <a4j:keepAlive> on that bean stops working.

                                • 13. Re: modalPanel strange behaviour when validating
                                  Ilya Shaikovsky Master

                                  1) just pass some "cleaning" flag and for example wrapper component id(e.g. form around inputs) and simply remove it from JSF tree in your listener. Or for example use the same "store" control actionListener. In the end when changes stored - get UIComponent instance from event iterate parents till find the form - and remove it from tree.

                                  2) bindings should not leave longer than request. if you will made 1) you will not need them at all.