Hi,

The rowIndex value changes when the enclosing table iterates over the DataModel. For example, when the table is *rendering*, it does:

  for(int index=0; ; ++index) {
    dataModel.setRowIndex(index);
    if (!dataModel.isRowAvailable)
      break;

    Object o = dataModel.getRowData();
    // render a row for object o
  }
  dataModel.setRowIndex(-1);

It does similar things during the "applyRequestValues" and "updateModel" phases. In particular, any listeners (including action methods) on the component which fire during these steps can assume that the rowIndex/rowData point to the relevant row/object *at the time the listener is invoked*. However the rowIndex is obviously not relevant outside of the listener callbacks.

I can't see what you are trying to achieve with your code below. Maybe you could describe the problem you're trying to solve?

Regards,

Simon

Harald Müller wrote:

List contentList = new ArrayList();
for (int i = 0 ; i<10;i++) {
  contentList.add("row " + i);
}
DataModel content = new ListDataModel(contentList);
hdt.setValue(content);


The console-output looks like:

[STDOUT] >>>>>>>>>> ==> ROWCOUNT 2
[STDOUT] >>>>>>>>>> ==> ROWINDEX 0
[STDOUT] >>>>>>>>>> ==> WRAPPEDDATA [EMAIL PROTECTED], [EMAIL PROTECTED]
[STDOUT] >>>>>>>>>> ==> ROWDATA [EMAIL PROTECTED]
[STDOUT] >>>>>>>>>> ==> ROWCOUNT 2
[STDOUT] >>>>>>>>>> ==> ROWINDEX 0
[STDOUT] >>>>>>>>>> ==> WRAPPEDDATA [EMAIL PROTECTED], [EMAIL PROTECTED]
[STDOUT] >>>>>>>>>> ==> ROWDATA [EMAIL PROTECTED]

As you can see there are 2 elements (wrappeddata) but the rowindex is not 
incremented during the iteration ... so I always get the first element/object 
back by using 'content.getRowData()'.

What am I doing wrong?

Thanks,
Harry



-----Ursprüngliche Nachricht-----
Von: Mathias Brökelmann [mailto:[EMAIL PROTECTED] Gesendet: Montag, 12. Dezember 2005 15:39
An: MyFaces Discussion
Betreff: Re: datatable - parameter passing - workaround?

use an instance of javax.faces.model.DataModel for the datatable´s
value. You can then use datamodel.getRowIndex() or
datamodel.getRowData() to get the current row value during the
iteration.

2005/12/12, Harald Müller <[EMAIL PROTECTED]>:
Hi!

My current (test)code to create a datatable in a dynamic created tab looks like 
this:


      // datatable
      UIData hdt = 
(HtmlDataTable)app.createComponent(HtmlDataTable.COMPONENT_TYPE);
      hdt.setId("hdtId1");
      hdt.setVar("hdtVar1");
      tab.getChildren().add(hdt);

      List content = new ArrayList();
      for (int i = 0 ; i<10;i++) {
        content.add("row " + i);
      }
      hdt.setValue(content);

      // create column
      UIColumn column = 
(UIColumn)app.createComponent(HtmlSimpleColumn.COMPONENT_TYPE);

      // create and add header
      UIOutput header = 
(UIOutput)app.createComponent(HtmlOutputText.COMPONENT_TYPE);
      header.setValue("Last Column");
      column.setHeader(header);

      // create and add content
      UIOutput text = 
(UIOutput)app.createComponent(HtmlOutputText.COMPONENT_TYPE);
      ValueBinding valueBinding = app.createValueBinding(#{hdtVar1})
      text.setValueBinding("value", valueBinding);
      column.getChildren().add(text);

      // add column
      hdt.getChildren().add(column);



Ok ... it is not possible to pass a parameter using "valuebinding" - so, there 
is no way
to call #{hdtVar1.name(mystring)} ... right?

Is there a way to call a bean-setter and set the current object (of the 
datatable-iteration)
in my bean, so that I'm able to call something like 'String whatever = 
hdtVar1.getName("mystring")'
and do a 'text.setValue(whatever)' from there?

Thanks,
Harry



--
Mathias



Reply via email to