10 Replies Latest reply on Sep 1, 2006 5:04 PM by dudududu

    2 DataModel questions

    dudududu Novice

      1) I would like to click on a button on a spesific row in my table and to show another table regarding this row , is it possible to use more then one DataModel in the same SB , otherwise can I send my DataModelSelection to another SB?or do I have to use the id as requestParam here?

      2)I would like to select few rows with a radio button and delete them all , is there any example how to do such a thing?


        • 1. Re: 2 DataModel questions
          hdslkf hklsdg Apprentice

          1) You can access the DataModelSelection from another bean or you can pass the id via request parameter. There are 2 examples in Seam showing both possibilities: The booking example and the blog example.

          2) sry, don't know ;)

          • 2. Re: 2 DataModel questions
            dudududu Novice

            thanks , another question is how to nested table , on row click I would like to open a table in the row beloe the clicked row , is it possible?


            • 3. Re: 2 DataModel questions
              hdslkf hklsdg Apprentice

              I've already seen an example with a nested table. But the problem is that you cannot put that nested table in a new ROW, since rows are "connected" only to the entities you iterate. But you can put a "sub-table" in a COLUMN.

              2) I had an idea about your second question. You might add a property delete (with default value false) to your listed entities and connect it to a SelectBooleanCheckbox. And at the bottom of the table you have a button "Delete selected items".

              <h:dataTable var="item" value="#{listOfItems}" ...
              ...<h:column><h:selectBooleanCheckbox value="#{item.delete}" /></h:column>...
              <h:commandButton value="Delete selected items" action="#{actionBean.deleteSelected}" />

               public String deleteSelected() {
               for (Item item: listOfItems)
               if (item.isDelete())
               return null;

              That's the plain idea. I think it should work, but maybe you need to regard things like e.g. reloading the list after deletion. And when having problems with detached entities use em.remove(em.find(Item.class, item.getId())); to work on managed entities.

              • 4. Re: 2 DataModel questions
                hdslkf hklsdg Apprentice

                better idea for deleteSelected, with a real delete query (that's faster):

                Vector idsToDelete = new Vector();
                for (Item item: listOfItems)
                if (idsToDelete.size() == 0)
                 return null;
                String ids = idsToDelete.toString(); //e.g. [1,4,5]
                ids = ids.substring(1, ids.length()-1); //e.g. 1,4,5 (brackets removed)
                String query = "delete from Item where id in (" + ids + ")";

                • 5. Re: 2 DataModel questions
                  dudududu Novice

                  Thanks - that's a great solution for my second problem ,
                  regarding nested tables , is it working with dataModel? did you see any Seam example for that?
                  can I use some how panelGrid in order to make it fill the all row?

                  • 6. Re: 2 DataModel questions
                    hdslkf hklsdg Apprentice

                    I haven't seen a Seam example for that. It's been something else but that's a long time ago.

                    Well, I just tried something out. I have a list of persons (my favorite example here in the seam forum *g*), and the person has friends (that are persons, too).

                    In that list of persons each person has a column where all friends are listed:

                    <h:dataTable var="person" value="#{personList.entries}">
                     <h:dataTable var="friend" value="#{person.friends}">

                    And it works, look:
                    | Stefan Berkmiller | bfo81 | Deutschland | Frank Hoyer |
                    | | | | Florian Mueller |
                    | | | | ... |
                    | .....

                    Problem here: The datatable is shown for every person. You may add a link "Show Friends" that stores the id. Well, look:

                    Your bean:
                    private Long personId;
                    private Long showFriendsForPersonId;
                    public String showFriends() {
                     showFriendsForPersonId = personId;
                     return null;

                    And then your Detail column should be like this:
                     <h:commandLink value="Show Friends" action="#{yourBean.showFriends}" rendered="#{showFriendsForPersonId != person.id}">
                     <f:param name="personId" value="#{person.id}">
                     <h:dataTable ... rendered="#{showFriendsForPersonId == person.id}">
                     shows friends, see above

                    Then there is always only one person whose friends are shown and the other persons have a "Show Friends" link.

                    Is that about what you're looking for?

                    • 7. Re: 2 DataModel questions
                      dudududu Novice

                      it's really great!
                      thanks a lot

                      I really wanted to show the friends list row below the reguler person row
                      but I guess it's impossible with the h:datatable.

                      • 8. Re: 2 DataModel questions
                        hdslkf hklsdg Apprentice

                        You could use ui:repeat and render the html table yourself.

                        I found a page that could be interesting for you (regarding that "conditional" row): http://www.nabble.com/%3Cc:if%3E-block-within-%3Cui:repeat%3E--t1855407.html

                        • 9. Re: 2 DataModel questions
                          Todd Main Newbie

                          On question #1, could you add some mockup HTML of what you're trying to do? It's easier to answer if we know exactly how you want to lay out the data.

                          • 10. Re: 2 DataModel questions
                            dudududu Novice

                            here is an example

                            <TABLE BORDER=2 CELLPADDING=4>
                            <TR> <TH COLSPAN=2>Suggestion #1</TH> </TR>
                            <TR> <TD>#1 status - Open</TD> <TD>12/12/2001</TD> </TR>
                            <TR> <TD>#1 status - Compiling</TD> <TD>3/12/2002</TD> </TR>
                            <TR> <TD>#1 status - Acctped</TD> <TD>5/10/2003</TD> </TR>
                            <TR> <TH COLSPAN=2>Suggestion #2</TH> </TR>
                            <TR> <TD>#2 status - Open</TD> <TD>10/12/2001</TD> </TR>
                            <TR> <TD>#2 status - Rejected</TD> <TD>5/01/2003</TD> </TR>

                            Suggestion #1 and suggestion #2 are the main/outer table and th statuses are the inner table for each element in the outer table