pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GB <nrganeshb...@yahoo.com>
Subject Display Bean Data In Table View
Date Sat, 08 May 2010 11:10:08 GMT

I have successfully completed one way trip from User To Database. I now just
want to display the ResultSet data. I did not find relevant examples on the
web/this-forum - hence this post. 

The application has the following architecture:

A bean named "Expense" with properties expenseId, expenseDate,
expenseDescription, expenseType, remarks, amount - with the relevant

A DB class that connects to the Oracle DB and fetches the expenses. The
relevant code is :

package rams.db;
public class DB {

    org.apache.pivot.collections.ArrayList expenseList = new ArrayList();
    BeanDictionary bd;// = new BeanDictionary();
    rams.entity.Expense expense;

    public ArrayList showExpenses()
        Connection conn = null;
        PreparedStatement pstmt = null;               
        String selectExpenseSql = "Select * from P_Expense";
        //java.util.ArrayList<Expense> expenseList = new
        try {
            conn = getOracleJDBCConnection();
        } catch (Exception e) {
            System.out.println("Exception Getting DB Connection ::: " + e);

        try {
            pstmt = conn.prepareStatement(selectExpenseSql);
            //run the sql on the table
            ResultSet rs = pstmt.executeQuery();
                int expenseId = rs.getInt("EXPENSEID");
                java.sql.Date expenseDate = rs.getDate("EXPENSEDATE");
                String expenseDescription =
                String expenseType = rs.getString("EXPENSETYPE");
                String remarks = rs.getString("REMARKS");
                double amount = rs.getDouble("AMOUNT");
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                String expdate = df.format(expenseDate);
                String amount_str = Double.toString(amount);
                String expenseId_str = String.valueOf(expenseId);               
                expense = new Expense(expenseId_str, expenseType,
expenseDescription, expenseType, remarks, amount_str);
                System.out.println("Created an instance of Expense Object");
                bd = new BeanDictionary(expense);
                System.out.println("Wrapped the instance of Expense Object
in BeanDictionary");
                System.out.println("Expense Added To The ExpenseList");
            System.out.println("Completed Expense ResultSet Processing");
        return expenseList;

The wtkx file:

<?xml version="1.0" encoding="UTF-8"?>
<Border xmlns="org.apache.pivot.wtk"
xmlns:wtkx="http://pivot.apache.org/wtkx" styles="{padding:6}">
<ScrollPane horizontalScrollBarPolicy="fill">
<TableView wtkx:id="expense"
<TableView.Column name="expenseId" width="135" headerData="Expense ID"/>
<TableView.Column name="expenseDate" width="135" headerData="Expense Date"/>
<TableView.Column name="expenseDescription" width="135"
<TableView.Column name="expenseType" width="135" headerData="Type"/>
<TableView.Column name="remarks" width="135" headerData="Remarks"/>
<TableView.Column name="amount" width="135" headerData="Amount"/>
<TableViewHeader tableView="$expense"/>

So my question is: How do I specify the tableData? 
In this particular case, the data is available in instances of Expensse bean
wrapped in Pivot Collections ArrayList. [One Expense bean instance per

In another case, if the data is made available in a JSON list how do I
specify? The example in the pivot site gives this format for a file that is
physically present in a location: tableData="@standings.json" 
However if I convert the resultset into JSON format, how do I specify in the
wtkx file?

Any help to resolve this would be of immense help to me. 

Thanks in Advance. 

View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Display-Bean-Data-In-Table-View-tp785464p785464.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

View raw message