|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
TableDataprovider in a dynamic created tableHi,
I'm having some trouble linking the input field in a table to the tabledataprovider when i'm generating the table from my backing bean. i am able to see the data in the table but when i edit it and submit it i still see the old data. I have tried everything but still cannot find the problem. Is this a known problem or am i doing something wrong? JSP: <webuijsf:table id="UserTable" binding="#{TestBean.userTable}"> <f:facet name="title"> <webuijsf:staticText text="Users"/> </f:facet> </webuijsf:table> <webuijsf:button id="testBVutton" text="Submit" actionExpression="#{TestBean.action}"></webuijsf:button> Backing Bean: package com.exmachina.quizengine.admin.beans; import com.exmachina.util.woodstock.MethodExpressionUtilities; import com.sun.data.provider.TableDataProvider; import com.sun.data.provider.impl.ObjectListDataProvider; import com.sun.webui.jsf.component.*; import java.util.ArrayList; import java.util.List; public class TestBean { private List<User> userList; private TableRowGroup tableRowGroup = null; private TableDataProvider provider = null; private Table userTable = null; public void setUserTable(Table userTable) { this.userTable = userTable; } public Table getUserTable() { if(userTable == null) { userTable = new Table(); userTable.setId("NameTable"); userTable.setVisible(true); userTable.setLite(false); userTable.setWidth("400"); userList = new ArrayList<User>(); userList.add(new User("Mark")); userList.add(new User("Remon")); tableRowGroup = createTableRowGroup(); userTable.getChildren().add(tableRowGroup); } return userTable; } public TableDataProvider getTableData() { if(provider==null) provider = new ObjectListDataProvider(userList); return provider; } public void action() { for (User user : userList) System.out.println("Old Name: " + user.getName()); ((ObjectListDataProvider)provider).commitChanges(); for (User user : userList) System.out.println("New Name: " + user.getName()); } public StaticText getText(String text) { StaticText staticText = new StaticText(); MethodExpressionUtilities.setValueExpression(staticText,"text", text); return staticText; } public TextField getTextField(String text) { TextField textField = new TextField(); textField.setTrim(true); textField.setColumns(80); MethodExpressionUtilities.setValueExpression(textField,"text", text); return textField; } public TableColumn getTableColumn(String id, String sort, String align, String width) { TableColumn col = new TableColumn(); col.setId(id); if(width!=null) col.setWidth(width); col.setSelectId(null); col.setHeaderText(null); col.setAlignKey(align); MethodExpressionUtilities.setValueExpression(col, "sort", sort); return col; } private TableRowGroup createTableRowGroup() { TableRowGroup rowGroup = new TableRowGroup(); rowGroup.setId("rowGroup1"); rowGroup.setSourceVar("user"); rowGroup.setHeaderText("Content block 1 "); MethodExpressionUtilities.setValueExpression(rowGroup,"sourceData", "#{TestBean.tableData}"); MethodExpressionUtilities.setValueExpression(rowGroup,"binding", "#{TestBean.tableRowGroup}"); TableColumn col1 = getTableColumn("col1", "#{user.value.name}", "textData", null); TextField textDataField = getTextField("#{user.value.name}"); col1.getChildren().add(textDataField); rowGroup.getChildren().add(col1); return rowGroup; } public TableDataProvider getProvider() { return provider; } public void setProvider(TableDataProvider provider) { this.provider = provider; } public TableRowGroup getTableRowGroup() { return tableRowGroup; } public void setTableRowGroup(TableRowGroup tableRowGroup) { this.tableRowGroup = tableRowGroup; } public class User { private String name; public User(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } } } --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free Forum Powered by Nabble | Forum Help |