14 Replies Latest reply on Jul 27, 2006 3:38 PM by gavin.king

    DataModel issue

    kh2ouija

      This may be a silly question but I haven't figured out the answer by myself, nor found any examples so please bear with me.

      Say I have the following domain model: Department -* Employee.

      I want to have a page that displays all departments, each with it's employees, and have a select button for each department *and* for each employee - on the same page. Something like this:

      <ui:repeat value="#{departments}" var="dep">
       h:button action="#{bean.selectDepartment}" value="#{dep.name}"/>
       <ui:repeat value="#{department.employees}" var="emp">
       <h:button action="#{bean.selectEmployee}" value="#{emp.name}"/>
       </ui:repeat>
      </ui:repeat>
      


      So far my relevant backing bean code looks like this:

      @DataModel
      private List<Department> departments;
      @DataModelSelection
      private Department selectedDepartment;
      @Factory
      private void findDepartments() {
       departments = departmentDAO.getAll();
      }
      
      public String selectDepartment() {
       // do stuff with selectedDepartment
      }
      
      public String selectEmployee() {
       // ???
      }
      


      How do I build on this to add the select functionality for employees?

      TIA

        • 1. Re: DataModel issue
          gavin.king

          <ui:repeat> is not a UIData, so you can't use the DataModel stuff.

          Use request parameters instead.

          • 2. Re: DataModel issue
            kh2ouija

            That's strange to hear, because I've used it before, instead of a <h:dataTable> and it *does* work...

            • 3. Re: DataModel issue
              gavin.king

              OK, Jacob says that <ui:repeat> _is_ aware of DataModels, even though it is not a UIData.

              Well, I'm not sure, it should in priniple work. Try debugging.

              You are welcome to submit a VERY SIMPLE test case to JIRA.

              • 4. Re: DataModel issue
                kh2ouija

                Well, if it's aware of DataModels, my initial question remains valid, how do I handle multiple (variable number of) DataModels? Or do I still have to use request parameters?

                • 5. Re: DataModel issue
                  kh2ouija

                  My initial question was not if it works.

                  It was this: the elements of my "main" DataModel have a OneToMany association (eg. Department -* Employee). How do I handle the employees as DataModels too? to have actions for them on the same page.. thanks.

                  • 6. Re: DataModel issue
                    gavin.king

                    You can put @DataMode on a method, if you like.

                    • 7. Re: DataModel issue
                      kh2ouija

                      Like, which method? Do you mean annotating the @OneToMany relationship Department.employees with @DataModel in the Department entity bean?

                      • 8. Re: DataModel issue
                        gavin.king

                        Add a getEmployees() method, or something.

                        • 9. Re: DataModel issue

                          I have a test case at http://www.jboss.com/index.html?module=bb&op=viewtopic&t=86726&postdays=0&postorder=asc&start=10#3961165 . It has one <ui:repeat> nested inside another. The outer one is generated by a @Factory method in a stateful session bean and the inner one by a method in an entity bean. The two kinds of entity beans are related by @ManyToMany. If nobody sees a problem with it then I'll submit it to JIRA.

                          • 10. Re: DataModel issue
                            gavin.king

                            Unless you are sure there is a bug in Seam, and you know the nature of the bug, you should not create any JIRA issues. Nothing in this thread indicates you have found any kind of bug.

                            • 11. Re: DataModel issue

                              In the other topic I wrote:

                              When pressing the "rename" buttons, the value that I expect to be injected is not there (the log.error() calls below are triggered).


                              for instance (and yes, sorry for not including it in the previous post):

                              2006-07-27 10:51:56,946 DEBUG [org.jboss.seam.Component] selected row: null

                              2006-07-27 10:51:56,946 DEBUG [org.jboss.seam.Component] instantiating Seam component: interpolator

                              2006-07-27 10:51:56,946 ERROR [com.orgmob.play.FubarManagerBean] FubarManagerBean.commitFoo() called but foo is null!

                              ...
                              2006-07-27 10:52:00,431 DEBUG [org.jboss.seam.Component] selected row: null

                              2006-07-27 10:52:00,431 DEBUG [org.jboss.seam.Component] instantiating Seam component: interpolator

                              2006-07-27 10:52:00,431 ERROR [com.orgmob.play.FubarManagerBean] FubarManagerBean.commitBar() called but bar is null!



                              When I press buttons that were generated using <ui:repeat> from a @DataModel, org.jboss.seam.Component says that no row was selected and where I expected @DataModelSelection to inject a value, the value is null. I think that is a bug. Am I in error?

                              • 12. Re: DataModel issue
                                gavin.king

                                I don't know the details of what works in facelets and what doesn't. You should ask about that in the facelets forum. But if it works when using h:dataTable, but not when using ui:repeat then it is definitely not a bug in Seam.

                                • 13. Re: DataModel issue

                                  I think the original post is conceptually wrong. <ui:repeat> is an iterator. It can iterate over lists of things, including DataModels. However it doesn't modify the model that is iterates over. For example it will never set a DataModel's selected row and using @DataModelSelection with it will never work.

                                  <ui:repeat> is a powerful substitue to using c:forEach. It is not a direct replacement for h:dataTable.

                                  Maybe I misunderstand the original question. If you need @DataModelSelection to work, you'll need to go back to h:dataTable.

                                  • 14. Re: DataModel issue
                                    gavin.king

                                    Note that there are plenty of other ways to implement clickable lists apart from @DataModelSelection. Arguably, using a request parameter (like in the blog example) is simply a better approach to begin with.