Search your blog

Sunday, May 02, 2010

How to remove row using removeRowWithKey in ADF

How to remove row from table using removeRowWithKey in ADF

In ADF we can delete row using delete operation .But it has a limitation to delete the specific row from table .It can only delete first row not to remove user specific row .I want to discuss how to delete user specific row from custom bean method using removeRowWithKey operation from command button .

Step1. You have to use two listener one is client Listener and Server Listener

<af:inputText value="#{row.bindings.TSexCode.inputValue}"
label="#{bindings.T02006View1.hints.TSexCode.label}"
required="#{bindings.T02006View1.hints.TSexCode.mandatory}"
columns="#{bindings.T02006View1.hints.TSexCode.displayWidth}"
maximumLength="#{bindings.T02006View1.hints.TSexCode.precision}"
shortDesc="#{bindings.T02006View1.hints.TSexCode.tooltip}"
id="it2">
<f:validator binding="#{row.bindings.TSexCode.validator}"/>

<af:clientListener method="getRowKeyStr" type="click" />
<af:serverListener type="clickOnRow" method="#{tb02006.getRowKeyStr}"/>
</af:inputText>

I am using javaScript function getRowKeyStr as a Client Listener method and click as an event .you can use any type of event for calling javaScript function .

<![CDATA[
<script>
function getRowKeyStr(event){
component=event.getSource();
alert("CALLED");
AdfCustomEvent.queue(component, "clickOnRow",{}, false);
}
</script>
]]>

Step 2.
From java Script function I am calling server Listener clickOnRow and it will call bean method getRowKeyStr().In the method I have hold the current row when user click on row then put into rowKey property.

public String getRowKeyStr(ClientEvent event){
System.out.println("getRowKeyStr Server Listener METHOD IS CALLING");
FacesContext context=FacesContext.getCurrentInstance();
Application app=context.getApplication();
ValueBinding bind=app.createValueBinding("#{row.rowKeyStr}");
/**
#{row.rowKeyStr} is a property value for current rowKey
**/
String rowKeyStr = (String)bind.getValue(context);
System.out.println("ROWKEYSTR:: "+rowKeyStr);
/*
put rowKeyStr into bean property rowKey
**/
setRowkey(rowKeyStr);

return rowkey;
}

Step3. Custom operation method remove () will delete row using removeRowWithKey operation.

public String remove(){
//String rowKeyVal=getRowKeyStr(ClientEvent event);
System.out.println("Remove METHOD IS CALLING:: "+getRowkey());
if (rowkey!=null){
DCBindingContainer binding=ADFUtils.getBindings();
OperationBinding opb=(OperationBinding)binding.getOperationBinding("removeRowWithKey");
opb.getParamsMap().put("rowKey", rowkey);
System.out.println("IS PARAM :: "+ opb.getParamsMap().containsKey("rowKey") );
System.out.println("PARAM VAL :: "+ opb.getParamsMap().get("rowKey") );
if(opb!=null){
System.out.println("ACTION NAME :: "+ opb.getName() );
opb.execute();
}
if (!opb.getErrors().isEmpty()) {
return null;
}
}

return "REMOVED";

}

1 comment:

  1. Nice Topic ,,Its Very Helpful for me

    pls give one example how set row using 'setCurrentRowWithKey'

    ReplyDelete