how to know which rows were edited in h:datatable

I have some input text rows in h:dataTable. I want to know which rows were edited by user so that I can update these rows in the database.
[145 byte] By [Jatin_Kulkarnia] at [2007-11-26 20:22:06]
# 1

Hello dear,

I think you can do that by using a Map. e.g

Map<Object[], Boolean> selections = new HashMap<Object[], Boolean>();

public String deleteSelection(){

try{

for (Object[] item: List) {

Boolean selected = selections.get(item);

if (selected!=null && selected) {

selections.put(item, false);

System.out.println("The deleted is: "+ item[0].toString());

// u can call any method u want

}

}

}catch(Exception e){

e.printStackTrace();

}

and on the JSF side use:

<h:dataTable id="list" value="#{userList}" var="User" >

<h:column>

<f:facet name="header">

<h:outputText value="Select" />

</f:facet>

<h:selectBooleanCheckbox value="#{selections[User]}" />

</h:column>

<h:column>

<f:facet name="header">

<h:outputText value="Name" />

</f:facet>

<h:outputText value="#{User.name}" />

</h:column>

</h:dataTable>

<h:commandButton ction="#{Action.deleteSelection}" value="Delete />

I hope it will do the trick;">

saifulislamkhana at 2007-7-10 0:47:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Implement valuechangelisteners.

public void listen(ValueChangeEvent event) {

if (!event.getOldValue().equals(event.getNewValue()) {

// the attached field has changed

}

}

BalusCa at 2007-7-10 0:47:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

I thought of implementing the valueChangeListener but that results in two problems

Firstly, the valueChagneListener is invoked before the update model phase, hence I don't have the datamodel(h:dataTable) at that stage.

Secondly, even if I get the dataModel somehow, how do I know the row that resulted in the valueChangeListener event being fired.

Jatin_Kulkarnia at 2007-7-10 0:47:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> Firstly, the valueChagneListener is invoked before

> the update model phase, hence I don't have the

> datamodel(h:dataTable) at that stage.

Reload the data and/or, preferably, put the data in session.

> Secondly, even if I get the dataModel somehow, how do

> I know the row that resulted in the

> valueChangeListener event being fired.

HtmlDataTable.getRowData() tells you.

BalusCa at 2007-7-10 0:47:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
I didn't understand what you mean by "Reload the data and/or, preferably, put the data in session". The data will come from screen edited by user.
Jatin_Kulkarnia at 2007-7-10 0:47:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Session scope instead of request scope, it is.
BalusCa at 2007-7-10 0:47:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
I still don't understand how to get the datamodel before the update model phase. Can you paste some sample code?
Jatin_Kulkarnia at 2007-7-10 0:47:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...