2 Replies Latest reply on Jan 6, 2014 5:53 AM by chaluwa

    Maximum Redirect Error from ErraiUI ??

    chaluwa

      I have a situation where navigating to a @Page from another @Page results in some kind of recursion and produces a "maximum redirect error" . Here's what I am trying to do.

      PostView fires a CDI event when it is shown, this causes PostPresenter to load data (posts). Each post is in a category and there's a view / presenter for them. So we also have CategoryPresenter and CategoryView.

       

      The PostView needs to display category data (say in a combo-box), so the CategoryPresenter listens for the CDI event fired by PostView when PostView is shown, and loads categories if they are not already loaded. This helps if the user visits PostView first. When categories are loaded, a CDI event is fired, PostView observes it and displays categories.

       

      The arrangement is kinda straight-forward, when the app loads and I click on the PostView link which is an injected TransitionActchor<PostView> element in a @Template component used as navbar, the PostView is displayed, showing posts and categories. However, if I proceed to click on the CategoryView link, which is also an an injected TransitionActchor<CategoryView> element in the same navbar component, then we end up in a recursion and the eventual error saying I have exhausted the maximum 99 redirects.

       

      The same thing happens if I start with CategoryView and then try to go to PostView. I have tried to simplify my setup with this Post / Category scenario here, any hints about the error and its solution ??

       

      @Page @Templated
      @Singleton
      public class PostView extends Composite {
      
        @Inject
        private Event<PostViewShown> shownEvt;
      
        @PageShown
        private void onPageShown() {
             shownEvt.fire(new PostViewShown());
        }
      
         ...
      }
      
      @Page @Templated
      @Singleton
      public class CategoryView extends Composite {
      
        @Inject
        private Event<CategoryViewShown> shownEvt;
      
        @PageShown
        private void onPageShown() {
             shownEvt.fire(new CategoryViewShown());
        }
      
         ...
      }
      
      @ApplicationScoped
      public class PostPresenter {
      
        @Inject
        private PostView display;
      
        private void onViewShown(@Observes PostViewShown e){
             LogUtil.log("load posts");
             ...
        }
      
        private void onCategoryData(@Observes CategoryData e){
             LogUtil.log("populate combo");
             ...
        }
      
      
      }
      
      @ApplicationScoped
      public class CategoryPresenter {
      
        @Inject
        private CategoryView display;
      
        @Inject
        private Event<CategoryData> dataEvt;
      
        private void onViewShown(@Observes CategoryViewShown e){
             LogUtil.log("load categories");
             loadCategories();
        }
      
        private void onPostViewShown(@Observes PostViewShown e){
             LogUtil.log("load categories for postview");
             loadCategories();
        }
      
        private void loadCategories(){
           // if data has not been loaded
           // load data, then fire CDI event that data is available
           dataEvt.fire(new CategoryData(list));
        }
      }
      
      
      
      
      
      
      
        • 1. Re: Maximum Redirect Error from ErraiUI ??
          mbarkley

          Hi Charles,

           

          I can't see anything that could cause this from the code you've posted. You could try figuring out what is causing the page navigation by setting a breakpoint in org.jboss.errai.ui.nav.client.local.Navigation on the method void navigate(Request<W>).

           

          Cheers.

          1 of 1 people found this helpful
          • 2. Re: Re: Maximum Redirect Error from ErraiUI ??
            chaluwa

            I set the breakpoint but could not pin down the issue. Recall that the @Singleton "view" (@Page) fire a CDI event in the @PageShown annotated method, which  is observed by @ApplicationScoped "presenter". When I commented the @PageShown methods in the views(event no longer fired, and data is not fetched), the recursive redirect issue does not come up.

             

            I observed that when I go to one of the views the first time everything works, but navigating to the second view having the @PageShown method causes a seemingly recursive redirect which leads to the error. So the question is, why are the CDI events fired from the @PageShown methods causing a recursive redirect? since commenting them (event firing) evades the error?

            http://ur1.ca/gcmih