Uploaded image for project: 'Wicket'
  1. Wicket
  2. WICKET-5911

Re-rendering page after exception in render phase does not call onBeforeRender()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 7.0.0-M6
    • 6.20.0, 7.0.0-M6
    • wicket
    • None

    Description

      (I sent this to the mailing list originaly, Sven Meier replied this is probably a bug and requested creating a JIRA issue for it.)

      I got page with structure like:

      • Page
        +- ListView – items
        \ - Footer panel

      Now the scenario (heavily simplified):

      One of the items in ListView gets exception from backend during onInitialize(). Required behavior in this case is to keep user on the page and replace ListView with a panel stating "Sorry, backend outage".

      So I catch the backend exception using aspect, replace view in the structure with the message panel and throw NonResettingRestartException to restart rendering the page.

      Page is rendered and seems OK, BUT I realize onBeforeRender() of Footer panel is never called.

      I debugged it and found the cause:

      ListView adds items in onPopulate() method which is called from onBeforeRender(). When page starts rendering, its onBeforeRender() is called. Page does:

      setFlag(FLAG_PREPARED_FOR_RENDER, true);

      and calls onBeforeRenderChildren(). This calls onBeforeRender() of ListView, causes exception, so that onBeforeRender() of the footer is not called this time.

      When second rendering is attempted, call flow gets to internalBeforeRender() of the page component. There is check:

      if ((determineVisibility()) && !getFlag(FLAG_RENDERING) && !getFlag(FLAG_PREPARED_FOR_RENDER)) {
      ...
      onBeforeRender();
      ...
      }

      But since FLAG_PREPARED_FOR_RENDER is set from previous attempt, onBeforeRender() of the page is not called (again) which means onBeforeRender() of the children is not called.

      I found that if I call

      markRendering(false);

      on the page before throwing the NonResettingRestartException, all goes well. But I am quite uneasy about this solution, so I have two questions:

      1) Cannot this cause some unforeseen troubles? (Supposing my components are correctly written so that their onBeforeRender() / onConfigure() / onAfterRender() procedures can be safely called multiple times.)

      2) Should not Wicket itself reset the FLAG_PREPARED_FOR_RENDER when response restarting exception is caught and processed?

      I created a Wicket quickstart project demonstrating the bug here: http://lemming.hofyland.cz/restartbug.zip

      Attachments

        Activity

          People

            svenmeier Sven Meier
            lemmingucwcz Michal Kara
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: