Help on create a list with dataview
This is the code: public class ListProductPage extends WebPage { public ListProductPage() { add(new Link(createLink) { /** * Go to the Edit page when the link is clicked, passing an empty * Product details */ public void onClick() { //setResponsePage(new EditProductPage(getPage(), 0)); } }); IColumn[] columns = new IColumn[3]; /* * This is a composite column, created by extending * FilteredAbstractColumn. This column adds a UserActionsPanel as its * cell contents. It also provides the go-and-clear filter control * panel. */ columns[0] = new FilteredAbstractColumn(new Model(Actions)) { // add the UserActionsPanel to the cell item public void populateItem(Item cellItem, String componentId, IModel model) { Product product = (Product) cellItem.getModelObject(); cellItem.add(new UserActionsPanel(componentId, product)); } // return the go-and-clear filter for the filter toolbar public Component getFilter(String componentId, FilterForm form) { return new GoAndClearFilter(componentId, form); } }; // creates a column with a text filter columns[1] = new TextFilteredPropertyColumn(new Model(Description), description, description); columns[2] = new TextFilteredPropertyColumn(new Model(Price), price); // set up data provider ProductDataProvider dataProvider = new ProductDataProvider(.); // create the data table DefaultDataTable products = new DefaultDataTable(products, Arrays.asList(columns), dataProvider, 10); //products.addTopToolbar(new FilterToolbar(products, dataProvider)); add(products); } public class ProductDataProvider extends SortableDataProvider implements IFilterStateLocator { /** dao that will be used to retrieve the list of Products */ private ProductDao dao; /** reuse the Product entity to store filter information */ private Product filter = new Product(); public Object getFilterState() { return filter; } public void setFilterState(Object state) { filter = (Product) state; } public ProductDataProvider(ProductDao dao) { this.dao = dao; // set the default sort setSort(description, true); } /** * Gets an iterator for the subset of Products. * * @param first *offset for the first row of data to retrieve * @param count *number of rows to retrieve * @return iterator capable of iterating over {first, first+count} Products */ public Iterator iterator(int first, int count) { QueryParam qp = null; SortParam sp = getSort(); qp = new QueryParam(first, count, sp.getProperty(), sp.isAscending()); return dao.find(qp, filter); } /** * Gets total number of items in the collection. * * @return total item count */ public int size() { return dao.count(filter); } /** * Converts the object in the collection to its model representation. A good * place to wrap the object in a detachable model. * * @param object *The object that needs to be wrapped * @return The model representation of the object */ public IModel model(Object object) { return new DetachableModelProduct((Product) object, dao); } } public class DetachableModelProduct extends LoadableDetachableModel { //make it transient, so that it will not get serialized. private transient Product product; private final ProductDao dao; private final Integer id; @Override public Object getObject() { return this.product; } public DetachableModelProduct(Product product, ProductDao dao) { this(product.getId(), dao); this.product = product; } public DetachableModelProduct(Integer id, ProductDao dao) { if (id == 0) { throw new IllegalArgumentException(); } this.id = id; this.dao = dao; } /** * Returns null to indicate there is no nested model. * @return Null */ public IModel getNestedModel() { return null; } /** * Uses the DAO to load the required product when the model is attatched to the request. */ protected void onAttach() { product = dao.load(id); } /** * Clear the reference to the product when the model is detatched. */ protected void onDetach() { product = null; } /** * Called after attatch to return the detatchable object. * @param component The component asking for the
Re: Help on create a list with dataview
are you using wicket 1.2??? -igor On Wed, Aug 6, 2008 at 7:33 AM, alex2008 [EMAIL PROTECTED] wrote: This is the code: public class ListProductPage extends WebPage { public ListProductPage() { add(new Link(createLink) { /** * Go to the Edit page when the link is clicked, passing an empty * Product details */ public void onClick() { //setResponsePage(new EditProductPage(getPage(), 0)); } }); IColumn[] columns = new IColumn[3]; /* * This is a composite column, created by extending * FilteredAbstractColumn. This column adds a UserActionsPanel as its * cell contents. It also provides the go-and-clear filter control * panel. */ columns[0] = new FilteredAbstractColumn(new Model(Actions)) { // add the UserActionsPanel to the cell item public void populateItem(Item cellItem, String componentId, IModel model) { Product product = (Product) cellItem.getModelObject(); cellItem.add(new UserActionsPanel(componentId, product)); } // return the go-and-clear filter for the filter toolbar public Component getFilter(String componentId, FilterForm form) { return new GoAndClearFilter(componentId, form); } }; // creates a column with a text filter columns[1] = new TextFilteredPropertyColumn(new Model(Description), description, description); columns[2] = new TextFilteredPropertyColumn(new Model(Price), price); // set up data provider ProductDataProvider dataProvider = new ProductDataProvider(.); // create the data table DefaultDataTable products = new DefaultDataTable(products, Arrays.asList(columns), dataProvider, 10); //products.addTopToolbar(new FilterToolbar(products, dataProvider)); add(products); } public class ProductDataProvider extends SortableDataProvider implements IFilterStateLocator { /** dao that will be used to retrieve the list of Products */ private ProductDao dao; /** reuse the Product entity to store filter information */ private Product filter = new Product(); public Object getFilterState() { return filter; } public void setFilterState(Object state) { filter = (Product) state; } public ProductDataProvider(ProductDao dao) { this.dao = dao; // set the default sort setSort(description, true); } /** * Gets an iterator for the subset of Products. * * @param first *offset for the first row of data to retrieve * @param count *number of rows to retrieve * @return iterator capable of iterating over {first, first+count} Products */ public Iterator iterator(int first, int count) { QueryParam qp = null; SortParam sp = getSort(); qp = new QueryParam(first, count, sp.getProperty(), sp.isAscending()); return dao.find(qp, filter); } /** * Gets total number of items in the collection. * * @return total item count */ public int size() { return dao.count(filter); } /** * Converts the object in the collection to its model representation. A good * place to wrap the object in a detachable model. * * @param object *The object that needs to be wrapped * @return The model representation of the object */ public IModel model(Object object) { return new DetachableModelProduct((Product) object, dao); } } public class DetachableModelProduct extends LoadableDetachableModel { //make it transient, so that it will not get serialized. private transient Product product; private final ProductDao dao; private final Integer id; @Override public Object getObject() { return this.product; } public DetachableModelProduct(Product product, ProductDao dao) { this(product.getId(), dao); this.product = product; } public DetachableModelProduct(Integer id, ProductDao dao) { if (id == 0) { throw new IllegalArgumentException(); } this.id = id; this.dao = dao; } /** * Returns null to indicate there is no nested model. * @return Null */ public IModel getNestedModel() { return null; } /** * Uses the DAO to load the required product when the model is attatched to the request. */ protected void onAttach() { product = dao.load(id); } /** * Clear the reference to the product when the model is detatched. */ protected void onDetach() { product = null; } /** * Called after attatch
Re: Help on create a list with dataview
No i'm using wicket 1.3.4. If there is a system to have a more simple code ... are you using wicket 1.2??? -igor -- View this message in context: http://www.nabble.com/Help-on-create-a-list-with-dataview-tp18852545p18853703.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help on create a list with dataview
i guess i am wondering where this code came from? looks like code from 1.2... /** * Returns null to indicate there is no nested model. * @return Null */ public IModel getNestedModel() { return null; } -igor On Wed, Aug 6, 2008 at 8:29 AM, alex2008 [EMAIL PROTECTED] wrote: No i'm using wicket 1.3.4. If there is a system to have a more simple code ... are you using wicket 1.2??? -igor -- View this message in context: http://www.nabble.com/Help-on-create-a-list-with-dataview-tp18852545p18853703.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help on create a list with dataview
I'm trying to customize an example but without success if there is a better way to get the same result with the 1.3.4 so much the better. Which part of the code would be modify? i guess i am wondering where this code came from? looks like code from 1.2... -- View this message in context: http://www.nabble.com/Help-on-create-a-list-with-dataview-tp18852545p18856946.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]