deleting a row in a dataTable --urgent please

Hi all,

I am new to Jsf and facelets. I need to implement the following conditions.

I have a dataTable. When I select a row and press a button (not in the table, but a separate one) , I need to delete that row. But the row should not be deleted in the backend.

Please I need help in this regard. Please help me in this.

[345 byte] By [PraveenMa] at [2007-11-26 18:46:51]
# 1
Just store the data list in session and don't reload the data after removing the object from the list.
BalusCa at 2007-7-9 6:20:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
well thanks for your reply. Please can you be little more clear with some dummy code
PraveenMa at 2007-7-9 6:20:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Assuming the datalist bean is session scoped:dtoList.remove(selectedDto);That's it. Just don't reload the data from the database.
BalusCa at 2007-7-9 6:20:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Thanks BaluSC. I tried with the following code. But didn't get it done. Can you please look at it.

I have three java files and one xhtml file.

DataObject.java

package here ....

public class DataObject

{

protected String customer ;

protected String location ;

protected String status ; protected int selectedRow ;

private DataObject()

{ }

private DataObject(String customer , String location, String status, int selectedaRow)

{ this.customer = customer ; ....... ; this.selectedRow = selectedRow ; }

*******************************************************************

And the setters and getters for the member variables are followed there

***************************************

2. DataLogic.java

package here...

import java.util.* ;

import *.*.DataObject ; // the full path here.

private static final DataLogic _instance = new DataLogic();

private ArrayList<DataObject> dataList = new ArrayList<DataObject>(); ;

private DataLogic()

{ addObjects(); }

public static DataLogic getInstance()

{return _instance; }

public ArrayList getDataList()

{ return dataList;}

public ArrayList<DataObject> addObjects()

{

dataList = new ArrayList<DataObject>();

String customer2 = "customer2"; String location2 = "sjc2";

String status2=" status2"; int selectedRow2 =-2 ;

DataObject Obj2 = new DataObject(customer2, location2,status2,selectedRow2);

dataList.add(Obj2);

DataObject Obj[] = new DataObject[10];

String customer[] = new String[10]; String location[] = new String[10];

String status[]= new String[10]; int selectedRow = -1 ;

for(int iCount=0; iCount<3; iCount++ )

{

customer[iCount] = "customer" + iCount ;

location[iCount] = "location" + iCount ;

status[iCount] = "status" + iCount ;

Obj[iCount] =new DataObject(customer[iCount],location[iCount], status[iCount],selectedRow);

dataList.add(Obj[iCount]);

}

return dataList ;

}

public String changeObjects(DataObject object, int value)

{

int howMany = 0;

String returnString = " begin ";

DataObject changeValueObject = new DataObject();

if(dataList!= null)

{

Iterator changeValue = dataList.iterator();

while(changeValue.hasNext()

{

changeValueObject = (DataObject)changeValue.next();

if(object.getCustomer() == changeValueObject.getCustomer() &&

object.getLocation() == changeValueObject.getLocation() &&

alarmObject.getStatus() == changeValueObject.getStatus() &&

)

{

changeValueObject.setSelectedRow(value) ;

howMany ++ ;

}

}

}

return returnString ;

}

}

**************************************************************

PraveenMa at 2007-7-9 6:20:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

package ...

import java.util.*;

import javax.faces.component.*;

import javax.faces.component.UIData;

import *.*.*.ata.DataObject;

import *.*.*.DataLogic;

public class DataHandler

{

private DataObject dataMask = new DataObject() ;

private UIData dataTable = new UIDataTable() ;

public DataHandler()

{ }

public void setDataMask(DataObject dataMask)

{this.dataMask = dataMask ; }

public DataObject getDataMask()

{return dataMask ;}

/* The UIData getters and setters. This is for capturing the selectedRow*/

public UIData getDataTable()

{ return dataTable;}

public void setDataTable(UIData dataTable)

{ this.dataTable = dataTable ; }

public ArrayList getData()

{

ArrayList<DataObject> data = DataLogic.getInstance().getDataList();

Iterator popUp = data.iterator();

/* If the selectedRow is -2 it means the selectedRow is masked so remove from the list */

while(popUp.hasNext())

{

DataObject object =((DataObject)popUp.next());

if(object.getSelectedRow()==-2)

{ popUp.remove(); }

}

return data;

}

public void maskLogic()

{

//call the changeObjects function to change the value of the selectedRow of the object

// to -2 for masking

if(dataMask!= null)

{ String returned = changeObjects(dataMask, -2) ; }

}

public void selectedRowLogic()

{

/* Get the row Selected from the table */

dataMask = (DataObject)dataTable.getDataTable().getRowData();

if(dataMask!= null)

{ String returned = changeObjects(dataMask, -3) ; }

}

}

*************************************************************

And finally the data.xhtml file.

<body>

<ui:composition template="appTemplateToolbarRightPane.xhtml">

<ui:define name="tabcontent">

<h:form>

<script>

function selectRow(Row)

{

var alrmrow = Row.childNodes[1].childNodes[0].value;

alert(alrmrow);

Row.childNodes[1].childNodes[0].value = -3 ;

}

</script>

<t:dataTable id="data_list"

width="70%"

var="dataMonitor"

value="#{dataHandler.data}"

binding="#{dataHandler.dataTable}"

rowOnClick="selectRow(this);"

summary="Loading the data list">

<t:column>

<f:facet name="header">

<h:outputLabel value="Customer" />

</f:facet>

<t:outputLabel value="#{dataMonitor.customer}" />

<t:inputHidden name="hiddenRow" value="#{dataMonitor.selectedRow}" />

<t:commandButton value="#{dataMonitor.selectedRow}"

action="#{dataHandler.selectedRowLogic}"

style="display:none" />

</t:column>

<t:column headerstyleClass="liveAlarmEventNameHeaderClass">

<f:facet name="header">

<h:outputLabel value="Location" />

</f:facet>

<h:outputLabel value="#{dataMonitor.location}" />

</t:column>

<t:column >

<f:facet name="header">

<h:outputLabel value="Status" />

</f:facet>

<h:outputLabel value="#{dataMonitor.status}" />

</t:column>

<t:column >

<f:facet name="header">

<h:outputLabel value="SelectedRow" />

</f:facet>

</t:column>

</t:dataTable> </div>

<div>

<t:commandButton value="Mask" action="#{dataHandler.maskLogic}" />

</div>

</h:form> </ui:define>

</ui:define>

</ui:composition>

</body>

</html>

So can u plese tell me whether this works or not.

PraveenMa at 2007-7-9 6:20:47 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...