Search your blog

Wednesday, May 12, 2010

How to create custom operation in ADF



In ADF there are many operations to perform of various functionality. To fulfill user requirement, we need to create custom operation. Now I will describe how to create custom operation .

Step 1: create a function into ApplicationModuleImp Class.

            String  getHelloMsg(){
                        String msg=”Hello”;
                        return msg;
            }
Step 2 Open AppModule -- > java --> client Interface then shuttle this function.

Step 3: From your Data Control you drug  your  function  in the page  and right click on your function  and select button.



Step 4: Right-click in the generated button then choose "Create Method Binding For Action" then create a managed bean.




Step 5: The commandButton Method will be like this
public String cb1_action() {
BindingContainer bindings = getBindings();
OperationBinding operationBinding = bindings.getOperationBinding("getHelloMsg ");
Object result = operationBinding.execute();
System.out.println("Result= " + result); // result will be the output of PL function
if (!operationBinding.getErrors().isEmpty()) {
return null;
}
return null;
}
Step 6- Save your Application then run index.jspx.

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";

}