Thursday, February 16, 2012

Programmatically Caputure Table values and update Viewobject

In case when data is coming from any webservice and you need to update any viewobject based on the updates the user is doing on UI table. The logic is to capture key of each row of UI table and find the key in the viewobject, get corresponding records and update the values as in table using below code. I have writtten it on button action.

public String cb1_action() {
// Add event code here...
RichTable table = this.getDtlTable();
System.out.println("Row Count:"+table.getRowCount());
Number keyValuePK;
// for (int i = 0; i < table.getRowCount(); i++)
// {
Row row = ((JUCtrlHierNodeBinding)table.getRowData(10)).getRow();
System.out.println(row.getAttribute(1)+" "+row.getAttribute(2));
keyValuePK = (Number)row.getAttribute("PrimaryFieldId"); //tenth row
System.out.println("Key Value: "+keyValuePK);
row.getAttribute("PrimaryFieldId");
//}

DCBindingContainer dbc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iter = (DCIteratorBinding)dbc.findIteratorBinding("IteratorName");
Key k1 = new Key(new Object[]{keyValuePK}); //employee id
Row[] r1 = iter.getViewObject().findByKey(k1, 1);
System.out.println(r1[0].getAttribute("PrimaryFieldId")+" "+r1[0].getAttribute("AnyotherDesc"));
r1[0].setAttribute("UpdateAnyAttr", 99999);

// row = iter.findRowsByKeyValues((Key[])row.getAttribute("SubmHeadId")) ;

return null;
}

Wednesday, February 15, 2012

Map Example

package view;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapExample {

public static void main(String[] args) {

Map mp=new HashMap();

// adding or set elements in Map by put method key and value pair
mp.put(new Integer(2), "Two");
mp.put(new Integer(1), "One");
mp.put(new Integer(3), "Three");
mp.put(new Integer(4), "Four");

//Get Map in Set interface to get key and value
Set s=mp.entrySet();

//Move next key and value of Map by iterator
Iterator it=s.iterator();

while(it.hasNext())
{
// key=value separator this by Map.Entry to get key and value
Map.Entry m =(Map.Entry)it.next();

// getKey is used to get key of Map
int key=(Integer)m.getKey();

// getValue is used to get value of key in Map
String value=(String)m.getValue();

System.out.println("Key :"+key+" Value :"+value);
}
System.out.println("Check Value: "+mp.containsValue("One"));
System.out.println("Check Key: "+mp.containsKey(1));

}
}

Tuesday, February 7, 2012

Search Criteria - View Criteria

Create view criterias against a view object (you can also have lov in the view criteria fields i.e. by defining the attribute as selectively required, as in screeshot).

In your datacontrol panel inside named criteria

, you will see this viewcriteria drag and drop it as ADF Query panel with table.