5 Replies Latest reply: Jul 9, 2012 12:27 AM by EEG RSS

    Save Tabular Form Session State Between Validations

    EEG
      Hello.

      I'm using Apex 4.1.0 on Oracle 10.2.0.5 and Oracle App Server 10g (mod_plsql).

      I manually created a tabular form (that is, it is not created via the Apex wizard) using collections. Here is the query:
      select apex_item.checkbox2(10,
                                 seq_id,
                                 'onclick="radio_highlight_row(this,' || '#ROWNUM#' || ')"',
                                 null,
                                 ':',
                                 'f10_' || '#ROWNUM#'
                                ) delete_row,
              apex_item.hidden (11, seq_id) || apex_item.text (12, c006, 30, 30, 'style="width:140px"', 'f12_' || '#ROWNUM#') display_text,
              apex_item.checkbox (13, '#ROWNUM#', null, decode(c007,'CHECKED','#ROWNUM#'),':','f13_' || '#ROWNUM#') defaulted,
              apex_item.hidden (14, c014) || apex_item.hidden (15, c020) || apex_item.select_list(16, null, 'Active;Y,InActive;N', 'style="color:darkred;"', 'NO', '%NULL%', '%', 'f16_' || '#ROWNUM#', NULL, 'NO') active_status
        from apex_collections
      where collection_name = 'COL_CHOICES'
      union all
      select apex_item.checkbox2(10,
                                 null,
                                 'onclick="radio_highlight_row(this,' || '#ROWNUM#' || ')"',
                                 null,
                                 ':',
                                 'f10_' || '#ROWNUM#'
                                ) delete_row,
              apex_item.hidden (11, null) || apex_item.text (12, null, 30, 30, 'style="width:140px"', 'f12_' || '#ROWNUM#') display_text,
              apex_item.checkbox (13, '#ROWNUM#', null, null, ':','f13_' || '#ROWNUM#') defaulted,
              apex_item.hidden (14, null) || apex_item.hidden (15, null) || apex_item.select_list(16, null, 'Active;Y,InActive;N', 'style="color:darkred;"', 'NO', '%NULL%', '%', 'f16_' || '#ROWNUM#', NULL, 'NO') active_status
        from dual
       where :P86_RADIO_ADD_ROW = '1'
      CONNECT BY LEVEL <= 1
      I also created a "GO" button that, when clicked, submits the page. A vaidation then fires that checks if all the "display_text" columns (this is associated with the array g_f12 in the above query) are filled-in. If not, then I display an error message.

      This is all working as expected.

      My problem is that, whenever the validation displays the error message, any changes users have made to any of the other form fields are lost. These fields immediately revert back to their values since the last time the "GO" button was clicked.

      Would anyone know how to basically save session state of my manually created tabular form fields after validation errors are displayed?

      Thank you.

      Elie
        • 1. Re: Save Tabular Form Session State Between Validations
          jrimblas
          Session state IS being save, but you're SQL is on a collection and the collection still has the previous values.
          You need to either save the values into your collection after submit or into a new collection that you can use to display the values entered after the validation fails. Either way, this process needs to happen before validations.
          Makes sense?
          -Jorge
          • 2. Re: Save Tabular Form Session State Between Validations
            EEG
            Hi, Jorge.

            Thank you for helping me.

            I think I understand what you're saying:

            Create a "temporary" collection - let's call it "COL_TEMP" - that serves to hold the current values actually being displayed in my manually created tabular form. These current values have not yet been saved into my main collection (this is the collection on which my tabular form is based - "COL_RADIO_CHOICES" seen in my query). It is these values that are being replaced with the previous data that is saved in my main collection since the last time the "GO" button was clicked and no validation errors occurred. If a validation error occurs, COL_TEMP would then be used to populate COL_RADIO_CHOICES with the current tabular form data.

            My problem in this is HOW to do this.

            Where in the flow of events can I populate COL_TEMP with the current data in my tabular form. When the "GO" button is clicked, the flow of events are:
            1) User fills fields in tabular form.
            2) User clicks "GO" button.
            3) Validations are run.
            4A) If [3] throws no errors, then:
                   4A1) My plsql process is run that saves currently populated tabular form data into collection COL_RADIO_CHOICES.
                   4A2) My tabular form re-displays with all of the current data that had been saved in COL_RADIO_CHOICES by [4A1].
            4B) If [3] does throw errors, then:
                   4B1) My plsql process that would normally save the current data displayed on screen (including any changes the user made) are rolled back.  In fact, *no* plsql processes would be run.
                   4B2) MY tabular re-displays with the data that had *previously* been saved in collection COL_RADIO_CHOICES because any of the user's data changes never was saved into this collection.
            If my understanding is correct, then where in this flow would I be able to save the current tabular form data (this includes any data changes the user may have made in the form fields just prior to clicking the "GO" button) into collection COL_TEMP?

            Thank you for your help/advice.

            Elie
            • 3. Re: Save Tabular Form Session State Between Validations
              EEG
              Hi, Jorge.

              I think I just solvedd my problem.

              Thanks to your advice, I forced myself to think through the flow of events and document them in my last post.

              I realized that if I create a "Before Header" plsql process that runs when the condition = "Inline Validation Errors Are Displayed", this process would populate my main query collection COL_RADIO_CHOICES with the current datachanges in the tabular form.

              Doing this solved my issue.

              Now, if a validation error is thrown, this plsql before headre process runs and populates my collection COL_RADIO_CHOICES. No "temporary" collection was needed.

              Thank you, Jorge, for your good help.

              It was much appreciated.

              Elie
              • 4. Re: Save Tabular Form Session State Between Validations
                jrimblas
                yay! you're welcome
                Glad you thought through it and found a good solution. I knew that either you could re-use your collection and update it or use a new one, but it all depends on your specifics, sometimes you can't just save the user changes on top of your collection until they are all valid.

                -Jorge
                • 5. Re: Save Tabular Form Session State Between Validations
                  EEG
                  Jorge,

                  Thank you, again.

                  It really helps to "stop, get some distance from the problem at hand, and think".

                  Elie