There's no right answer; there are many solutions. It just has to be something that you can use to look up the column value for the row object.
>From what you've said before, one possibility is to use a column data model that contains the Integers 0 to 7 (or MaxPrivs-1). Then you can use Object row = rowDataModel.getRowData() Number indexNumber = (Number)columnDataModel.getRowData() Object row.columnValueAtIndex(indexNumber); On 11/8/05, Enrique Medina <[EMAIL PROTECTED]> wrote: > I understand, but there is still something I cannot see... > > You use a data model as value to the <t:columns> tag, and then that data > model is used to identify the column selected. So my question is: what kind > of data model should I use so later any of my child objects can be > identified? > > 2005/11/8, Mike Kienenberger <[EMAIL PROTECTED]>: > > In my example, the columns were independent of the rows. > > > > In your case, you'll have to first compute the maximum size. > > > > Using my code, I'd do it something like this: > > > > ============== > > private columnList = null; > > > > public List getColumnList() { > > if (null == columnList) { > > List rowList = getRowList(); > > // iterate over the row list and determine the value for > > maxColumnCount > > columnList = > createColumnListOfSize(maxColumnCount); > > } > > > > return columnList; > > } > > > > public boolean getValueFor(Object rowObject, Object columnObject) { > > int columnIndex = columnObject.findIndex(); > > if (columnIndex >= rowObject.getColumnList.size ()) return > emptyObject; > > else return rowObject.getColumnList(columnIndex); > > } > > ============== > > > > Obviously, my model isn't a direct fit to what you're doing, but the > > basic logic is still the same. The first time you need it, compute > > the max-size column list. Then each time a row/column item is > > accessed, return the column in the row if the row has that many > > elements, or return an empty object if it doesn't. > > > > -Mike > > > > On 11/7/05, Enrique Medina < [EMAIL PROTECTED]> wrote: > > > But what should I use in my example as "value" in the <t:columns> tag? I > > > mean, how can I ensure that for each row each of the child objects will > be > > > called? How does JSF knows it? > > > > > > > > > 2005/11/7, Mike Kienenberger <[EMAIL PROTECTED]>: > > > > My suggestion would be to adjust your column model so it always has 8 > > > > (or MAX) values for each row, and simply return "empty" (whatever that > > > > means in your component) data for the remaining values. > > > > > > > > Alternatively, you could try: > > > > > > > > <t:columns> > > > > <h:panelgroup> > > > > <UIInput rendered="#{!column.empty}"> > > > > <h:outputText value="" rendered="#{column.empty }"> > > > > </h:panelgroup> > > > > </t:columns> > > > > > > > > On 11/7/05, Enrique Medina <[EMAIL PROTECTED]> wrote: > > > > > Just to clarify with a concrete example: > > > > > > > > > > Imagine in your example of users and privileges that you want to > show > > > as > > > > > rows the users' names, and as columns simply each user's privileges, > but > > > the > > > > > first user (row) has 3 privileges, the second one has 5, the third > one > > > has 8 > > > > > and the fourth one has 2. The maximum columns will be 8 (as of the > max > > > > > number of privileges per user), but not all the columns in all the > rows > > > will > > > > > be printed... > > > > > > > > > > 2005/11/7, Enrique Medina <[EMAIL PROTECTED]>: > > > > > > Great approach! > > > > > > > > > > > > Just one comment: while your dynamic number of columns > > > (allPrivilegeList) > > > > > is known, mine is not known, and depends as commented before on the > > > maximum > > > > > size of the collections of the parent objects. For example, in your > > > example, > > > > > instead of showing all the possible values of the privileges as > column > > > > > headers and then showing whether the user has the privilege or not, > > > imagine > > > > > my approach: you need to have as many columns as the maximum > elements in > > > any > > > > > of the collections of the parent objects that populate the data > table. > > > > > > > > > > > > Do you know what I mean? > > > > > > > > > > > > > > > > > > > > > > > > 2005/11/7, Mike Kienenberger < [EMAIL PROTECTED] >: > > > > > > > I always point out this example code I made as an example of > > > creating > > > > > > > a composite component, but it also has a good example of using a > > > > > > > combined row&column data model. > > > > > > > > > > > > > > Take a look at > RowAndColumnRelationshipsBackingBean > > > > > which provides the > > > > > > > row model and the column model. I then implement the interface > in > > > > > > > RowAndColumnRelationshipsDataModel and can plug > any > > > > > number of models > > > > > > > into my page. > > > > > > > > > > > > > > I no longer use any of the other classes since I've switched > over to > > > > > facelets. > > > > > > > Instead, I now just use this page code. I've removed some of > the > > > > > > > decorations (like the dataScrollers), but these three files > > > > > > > (RowAndColumnRelationshipsBackingBean, > > > > > > > RowAndColumnRelationshipsDataModel, and the > code > > > below) > > > > > should > > > > > > > demonstrate it sufficiently. > > > > > > > > > > > > > > This level of indirection might be overkill for what you're > doing, > > > so > > > > > > > you might simply rewrite how > > > > > RowAndColumnRelationshipsBackingBean > > > > > > > works internally. > > > > > > > > > > > > > > "backingBean" is a > > > RowAndColumnRelationshipsBackingBean > > > > > configured > > > > > > > with another bean that implements a > > > > > > > RowAndColumnRelationshipsDataModel. > > > > > > > > > > > > > > <x:dataTable id="datatable" > > > > > > > > > > value="#{backingBean.rowDataModel}" > > > > > > > var="row" > > > > > > > > preserveDataModel="false" > > > > > > > > > > > > > > > > > > > > > > <f:facet name="footer"> > > > > > > > <h:panelGroup> > > > > > > > <h:commandButton value="Update" > > > > > > > actionListener="#{backingBean.update}"/> > > > > > > > </h:panelGroup> > > > > > > > </f:facet> > > > > > > > <h:column> > > > > > > > <h:outputText value="#{row.rowName}"/> > > > > > > > </h:column> > > > > > > > <x:columns > > > > > > > value="#{backingBean.columnDataModel}" > > > > > > > var="column"> > > > > > > > <f:facet name="header"> > > > > > > > <h:outputText value="#{column.columnName}"/> > > > > > > > </f:facet> > > > > > > > <h:selectBooleanCheckbox > > > > > > > value="#{backingBean.relationshipValue }"/> > > > > > > > </x:columns> > > > > > > > </x:dataTable> > > > > > > > > > > > > > > > > > > > > > On 11/7/05, Enrique Medina < [EMAIL PROTECTED]> wrote: > > > > > > > > I understand Mike :-) > > > > > > > > > > > > > > > > So if I have a collection of parent objects, which in turn > each > > > > > parent > > > > > > > > object has a collection of other child objects, then I can > show a > > > > > table > > > > > > > > where the first column is fixed and contains vertically the > list > > > of > > > > > the > > > > > > > > parent objects, but for each row, the columns are dynamic and > can > > > show > > > > > the > > > > > > > > collection of child objects for each parent. Is that right? > > > > > > > > > > > > > > > > What should I use for each data model, I mean, the collection > of > > > > > parent > > > > > > > > objects to populate the main data table and the child > collection > > > of > > > > > each > > > > > > > > parent object to populate the columns component? Would that > make > > > > > sense? If I > > > > > > > > edit all the child objects, would the getRowData from the main > > > table > > > > > return > > > > > > > > me a parent object with its colllection modified so I could > > > rapidly > > > > > persist > > > > > > > > it? > > > > > > > > > > > > > > > > Thanks for your support ;-) > > > > > > > > > > > > > > > > > > > > > > > > 2005/11/7, Mike Kienenberger < [EMAIL PROTECTED]>: > > > > > > > > > t:columns does exactly that -- it takes a collection of data > and > > > > > makes > > > > > > > > > as many columns as items in the collection. > > > > > > > > > > > > > > > > > > In fact, you can think of t:columns as a data table rotated > 90 > > > > > degrees. > > > > > > > > > The t:columns component, like dataTable is a subclass of > UIData. > > > > > The > > > > > > > > > "trick" is that when t:columns renders a "row" it uses <td> > > > instead > > > > > of > > > > > > > > > <tr>. It's not quite that simple, but from the perspective > of > > > an > > > > > > > > > end-user, it can be treated as such. > > > > > > > > > > > > > > > > > > In fact, t:columns API is a little bit confusing since > > > getRowData() > > > > > > > > > really means getColumnData and getRowIndex() really means > > > > > > > > > getColumnIndex(). Again, that's because it's effectively a > > > nested > > > > > > > > > dataTable that renders td tags instead of tr tags. > > > > > > > > > > > > > > > > > > I hope that helps! > > > > > > > > > > > > > > > > > > On 11/7/05, Enrique Medina < [EMAIL PROTECTED] > wrote: > > > > > > > > > > Well, maybe I have explained myself badly, but obviously > the > > > > > number of > > > > > > > > rows, > > > > > > > > > > although dynamic, would be fixed ( i.e. the maximum of > all). > > > > > > > > > > > > > > > > > > > > The main problem I have is that the data for the columns > is a > > > > > > > > collection > > > > > > > > > > rather than a fixed number of properties in a class; i.e . > it > > > > > represents > > > > > > > > an > > > > > > > > > > object with a collection of objects inside it, and each > > > element of > > > > > the > > > > > > > > > > collection is the data I want to show for every column. > > > > > > > > > > > > > > > > > > > > 2005/11/7, Mike Kienenberger < [EMAIL PROTECTED]>: > > > > > > > > > > > I don't know of a component that generates a different > > > number of > > > > > > > > > > > columns for each row. Columns allows a dynamic number > of > > > > > columns, > > > > > > > > > > > but the number is still the same for every row. > > > > > > > > > > > > > > > > > > > > > > What kind of html would you expect it to generate, since > a > > > > > standard > > > > > > > > > > > html table expects a set number of columns? > > > > > > > > > > > > > > > > > > > > > > Probably, your best bet is to go with a t:dataList which > > > > > operates on > > > > > > > > > > > row data, but doesn't render any particular output. > Then, > > > for > > > > > each > > > > > > > > > > > row, you can output whatever kind of html that you need. > > > > > > > > > > > > > > > > > > > > > > On 11/7/05, Enrique Medina < [EMAIL PROTECTED] > > wrote: > > > > > > > > > > > > Hi, > > > > > > > > > > > > > > > > > > > > > > > > I want to create a special data table where the > number of > > > > > columns > > > > > > > > is > > > > > > > > > > > > variable in each row depending of the value of the > object > > > > > being > > > > > > > > painted. > > > > > > > > > > > > > > > > > > > > > > > > I've been looking at the HtmlColumns component, but > > > although > > > > > being > > > > > > > > > > dynamic, > > > > > > > > > > > > I can't see how I can define different number of > columns > > > for > > > > > each > > > > > > > > row. > > > > > > > > > > > > > > > > > > > > > > > > Any idea of how to accomplish this kind of data > sheet? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >