2 Replies Latest reply on Jan 7, 2008 1:46 PM by fromage

    Bijection and interfaces

    fromage

      Hello,


      I have two entities (Foo and Bar) implementing a common interface (Commentable) which has this method:


      public interface Commentable{
       List<Comment> getComments();
      }



      I have then a page to show details about Foo entities and another page for Bar entities. Both pages want to show the list of comments though. Each of these page defines a bijected PAGE value for the current Foo, or the current Bar:


      public class FooBean{
       @Out(scope = ScopeType.PAGE) Foo foo;
      }
      
      public class BarBean{
       @Out(scope = ScopeType.PAGE) Bar bar;
      }



      How can I write a CommentBean which would return the list of comments for any Foo or Bar entity?


      public class CommentBean{
       @In(required = false) Foo foo;
       @In(required = false) Bar bar;
       @DataModel List<Comment> commentList;
       @Factory("commentList")
       public void initCommentList(){
        // get the list of comments for foo or bar
       }
      }



      Right now I'm thinking I try to inject both and whichever gets a value is the right object to work on. But I'm not sure this is the correct way to do it.
      Of course this is a simplification of the problem, my CommentBean has more work to do on Commentable objects.


      Ideally I would want something like this in CommentBean:


      @In(fromValue = "foo OR bar") Commentable commentable;



      Or similar but using less ugly syntax :)