You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by GB <nr...@yahoo.com> on 2010/05/08 13:09:06 UTC
Display Bean Data In Table View
Friends,
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
getters/setters.
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
ArrayList<Expense>();
try {
conn = getOracleJDBCConnection();
} catch (Exception e) {
System.out.println("Exception Getting DB Connection ::: " + e);
}
try {
pstmt = conn.prepareStatement(selectExpenseSql);
pstmt.setFetchSize(10);
//run the sql on the table
ResultSet rs = pstmt.executeQuery();
while(rs.next())
{
int expenseId = rs.getInt("EXPENSEID");
java.sql.Date expenseDate = rs.getDate("EXPENSEDATE");
String expenseDescription =
rs.getString("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");
expenseList.add(bd);
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}">
<content>
<ScrollPane horizontalScrollBarPolicy="fill">
<view>
<TableView wtkx:id="expense"
xmlns:collections="org.apache.pivot.collections"
tableData="rams.db.DB.expenseList">
<columns>
<TableView.Column name="expenseId" width="135" headerData="Expense ID"/>
<TableView.Column name="expenseDate" width="135" headerData="Expense Date"/>
<TableView.Column name="expenseDescription" width="135"
headerData="Description"/>
<TableView.Column name="expenseType" width="135" headerData="Type"/>
<TableView.Column name="remarks" width="135" headerData="Remarks"/>
<TableView.Column name="amount" width="135" headerData="Amount"/>
</columns>
</TableView>
</view>
<columnHeader>
<TableViewHeader tableView="$expense"/>
</columnHeader>
</ScrollPane>
</content>
</Border>
So my question is: How do I specify the tableData?
Question-1:
In this particular case, the data is available in instances of Expensse bean
wrapped in Pivot Collections ArrayList. [One Expense bean instance per
record/row]
Question-2:
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.
GB
--
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Display-Bean-Data-In-Table-View-tp785461p785461.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.