Row index in data table confusion

Hi,

(Warning, confused noob.)

I'm trying to get the indices of rows in a datatable.

I was following the advice on this thread:

http://forum.java.sun.com/thread.jspa?forumID=427&threadID=549084

The problem is, in IE, my two rows both show "0" for row index, and in FF my rows show "0" and "2" for row index.

Here's what my bean looks like:

publicclass MyBean{

private MyData[] data;// holds the actual data

private ArrayDataModel dataModel;

private UIData dataTable;

// This was already here when I got this class

public DataModel getData(){

dataModel =new ArrayDataModel(data);

return dataModel;

}

// These I added upon the advice of thread.jspa?forumID=427&threadID=549084

public UIData getDataTable(){

return dataTable;

}

publicvoid setRelationshipTable(UIData dataTable){

this.dataTable = dataTable;

}

}

Here's what my data table looks like:

<h:dataTable value="#{MyBean.data}" binding="#{MyBean.dataTable}" var="doc">

<h:column>

<f:facet name="header"> <h:outputText value="#{msgs.someColumnHeader}"/> </f:facet>

<h:selectBooleanCheckbox id="accepted" onclick="return editData(#{MyBean.data.rowIndex + 1})"/>

<h:outputText id="indexOutput" value="#{MyBean.dataTable.rowIndex + 1}"/>

</h:column>

...

</h:dataTable>

As you can see, I tried getting "rowIndex" from both "DataModel" and "UIData", but neither gives me what I need.

Hubert

ps. do I really need three variables (data/dataModel/dataTable) for the same set of data?

[2642 byte] By [hrabagoa] at [2007-10-2 9:17:48]
# 1

Hi,

did you solve this problem?

I don't understand how it can work to use the expression "#{MyBean.data}" in the JSP. I presume it will call getData(), which returns something ('dataModel') of a different type than the property 'data'. I thought that for backing bean properties to work, the type of the field itself must match the type returned by the accessor. Just curious about that.

Personally I'm interested in whether you can also access the row index from within the getDataTable() method in the bean. If you were to build the datatable (UIData) programmatically in this method, rather than in the JSP as you have done, would calling something like data.getRowIndex() allow me to add a different piece of data for each cell in a column?

zahira_dandaa at 2007-7-16 23:24:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
If you have a model, then you add directly in the model. You don't need the RowIndex.You can access to the selected row like this :getModel().getRowData()
pringia at 2007-7-16 23:24:53 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...