Announcement Announcement Module
Collapse
No announcement yet.
@Order not working for me Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @Order not working for me

    Hi all,

    I have some Beans like this:

    Code:
    @Component
    @Scope(value = RequestAttributes.REFERENCE_SESSION)
    @Order(1)
    public class FirstPage extends CustomComponent implements Page { ... }
    
    @Component
    @Scope(value = RequestAttributes.REFERENCE_SESSION)
    @Order(2)
    public class SecondPage extends CustomComponent implements Page { ... }

    Then in my NavigationManager I'm using this Beans:

    Code:
    @Component
    @Scope(value = RequestAttributes.REFERENCE_SESSION)
    public class NavigationManager {
    
      private static final Log LOG = LogFactory.getLog(NavigationManager.class);
    
      @Autowired
      //List<Page> pages = Lists.newArrayList();
      List<Page> pages;
    
      private Page currentPage;
    
      public NavigationManager() {
        System.out.println("1:"+pages);
        if (!pages.isEmpty()) {
          currentPage = pages.get(0);
        }
      }
    
      public Page getCurrentPage() {
        System.out.println("2:" + pages);
        return currentPage;
      }
    Two problems:

    1. at creation time (NavigationManager constructor) : pages == null
    2. then later (2) pages are available but in the wrong order

    What's wrong?

    Regards
    Andreas
    Last edited by ahoehma; Jul 27th, 2011, 03:30 AM.

  • #2
    Workaround

    Code:
    @PostConstruct
      void initPages() {
        // XXX http://forum.springsource.org/showth...working-for-me
        Collections.sort(pages, new Comparator<Page>() {
    
          @Override
          public int compare(final Page o1, final Page o2) {
            final Integer order1 = (Integer) AnnotationUtils.getValue(AnnotationUtils.findAnnotation(o1.getClass(),
                Order.class));
            final Integer order2 = (Integer) AnnotationUtils.getValue(AnnotationUtils.findAnnotation(o2.getClass(),
                Order.class));
            return order1.compareTo(order2);
          }
        });
        currentPage = Iterables.getFirst(pages, null);
      }
    Last edited by ahoehma; Jul 27th, 2011, 03:30 AM.

    Comment


    • #3
      Use [ code][/code ] tags when posting code... The @Order annotation isn't designed/meant to be used in that way, it is used to determine the order in which to apply advices/bean(factory)post processors.

      Comment

      Working...
      X