3 Replies Latest reply on May 21, 2009 2:26 PM by ariefzj

    Component in datatable restore incorrect state

    ariefz

      Hi,

      We have created a custom JSF component using the CDK which extends from UIInput which we name it Popup (for example). The Popup has an attribute that is similar to UIInput's value where we called it HiddenField.

      In the decode method of the popup's rendererBase we have something like this:

      String submittedValue = requestParams.get(clientId);
      if (submittedValue != null) {
       popup.setSubmittedValue(submittedValue);
      }
      String oldHiddenValue = popup.getHiddenField();
      if (oldHiddenValue == null) {
       oldHiddenValue = "";
      }
      String newHiddenValue = requestParams.get(clientId + UIPopup.HIDDEN_FIELD);
      if (newHiddenValue == null) {
       newHiddenValue = "";
      }
      popup.setHiddenField(newHiddenValue);
      


      By having "popup.setHiddenField()", the component should remember the value during the next RESTORE_VIEW phase and It does remember :)

      Unfortunately, it doesn't remember correctly once we use the popup component in a datatable.

      For example:
      In the datatable we have for 4 rows of data and each row will contain this popup. First 3 rows are readonly while the last one is editable(new row). Filled up the last popup and with some ajax-submit, the value will be kept in the server. (no db save yet).

      Then user wanted to clear out the last value. After clearing it and do an ajax-submit.
      Unfortunately, during the decode of the 1st row's popup, somehow it got the 4th row's popup's hiddenvalue.. thus our expected result goes wrong.

      With some debugging we noticed this:
      1. During saveState, the component's clientId is in this format: "form:table:rowIdx:compId".
      2. During restoreState, the component's clientId is still null and sometimes we could see it returning this format: "form:table:compId" (excluding row index)

      Does anyone know what have we done wrong here. Is this JSF bug or have we created the component incorrectly (especially the hiddenField property).

      Thanks in advance

        • 1. Re: Component in datatable restore incorrect state
          ariefz

           

          With some debugging we noticed this:
          1. During saveState, the component's clientId is in this format: "form:table:rowIdx:compId".
          2. During restoreState, the component's clientId is still null and sometimes we could see it returning this format: "form:table:compId" (excluding row index)


          Sorry, wrong input.
          Actually during the saveState, JSF recognize the component's clientId as "form:table:compId" (excluding row index).

          And one more thing, even though i have the component in each row, but the debugger only enter the component saveState once. Does JSF exclude read-only component during saveState?

          My environment:
          RF-3.3.0-GA
          JSF-1.2_11

          Thanks

          • 2. Re: Component in datatable restore incorrect state
            nbelaevski

            Please take a look at org.ajax4jsf.component.UIDataAdaptor.saveChildState(FacesContext, UIComponent, Map<String, SavedState>) method - your component should save the whole state properly.

            • 3. Re: Component in datatable restore incorrect state
              ariefzj

              My bad.

              After looking at your reply, the problem could be related to a 3rd party table component that we are using. All this while i have been looking,testing,searching within my own little component.

              Thanks for the hint. I will post this in their forum then.

              Thanks again.