-
1. Re: 2 DataModel questions
bfo81 Aug 31, 2006 6:52 AM (in response to mrohad)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
mrohad Aug 31, 2006 6:56 AM (in response to mrohad)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?
thanks -
3. Re: 2 DataModel questions
bfo81 Aug 31, 2006 7:23 AM (in response to mrohad)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:dataTable> <h:commandButton value="Delete selected items" action="#{actionBean.deleteSelected}" />
@Name("actionBean") ... public String deleteSelected() { for (Item item: listOfItems) if (item.isDelete()) em.remove(item); 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
bfo81 Aug 31, 2006 7:31 AM (in response to mrohad)better idea for deleteSelected, with a real delete query (that's faster):
Vector idsToDelete = new Vector(); for (Item item: listOfItems) if(item.isDelete()) idsToDelete.add(item.getId()); 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 + ")"; em.createQuery(query).executeUpdate();
-
5. Re: 2 DataModel questions
mrohad Aug 31, 2006 7:33 AM (in response to mrohad)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
bfo81 Aug 31, 2006 8:53 AM (in response to mrohad)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:column>#{person.name}</h:column> <h:column>#{person.nick}</h:column> <h:column>#{person.country}</h:column> <h:column> <h:dataTable var="friend" value="#{person.friends}"> <h:column>#{friend.name}</h:column> </h:dataTable> </h:column> </h:dataTable>
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: @RequestParameter private Long personId; @Out(required=false) private Long showFriendsForPersonId; public String showFriends() { showFriendsForPersonId = personId; return null; }
And then your Detail column should be like this:<h:column> <h:commandLink value="Show Friends" action="#{yourBean.showFriends}" rendered="#{showFriendsForPersonId != person.id}"> <f:param name="personId" value="#{person.id}"> </h:commandLink> <h:dataTable ... rendered="#{showFriendsForPersonId == person.id}"> shows friends, see above </h:column> ...
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
mrohad Aug 31, 2006 9:04 AM (in response to mrohad)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
bfo81 Sep 1, 2006 6:18 AM (in response to mrohad)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
texan Sep 1, 2006 10:29 AM (in response to mrohad)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
mrohad Sep 1, 2006 5:04 PM (in response to mrohad)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> </TABLE>
Suggestion #1 and suggestion #2 are the main/outer table and th statuses are the inner table for each element in the outer table