Hi, I'm looking to better a solution I have. This post is for the experts to point to a more elegant solution if possible. I wanted to use Fragment within a Grid. Not sure I did the best job possible. Here are the details :::
There was a problem I had earlier with Grid Views being symmetric. I solved that with my own Assymentric Grid View (yet to submit a JIRA for it). http://apache-wicket.1842946.n4.nabble.com/GridView-for-A-Symmetric-tables-issues-td2953859.html#a2968709 .. this Grid is used to display products. Here is the site I programmed on check the catalog section out. http://trueso.co.in You will notice, the main Cell on the top left corner has a caption and a "Next Icon". I was putting this separate with a floating div, and it was causing issues in some browsers. So I wanted to make that section into a Table. Earlier i just simply put the Image in the Grid, and in the markup I super impose a <DIV> to show the caption. But I dont like that. So i changed it to use fragments.... Vetrans will be familiar with the "populateItem" in the GridView! BTW all this code is within a Panel. Conceptually, "according tot he book" Fragments are used for a Page customization. But I felt it to be neat to be used from a Panel, where you can customize the fragment per customer. /** * Render the Product Grid */ @Override protected DataViewBase<Product> createGrid(SortableDataProvider<Product> provider) { ... final WebMarkupContainer grid = this; final AssymetricGridView<Product> gridView = new AssymetricGridView<Product>("gridView", provider, defaultRowsNum, defaultColsNum, asymDesc) { @Override protected final void populateItem(final Item<Product> item) { final Product product = item.getModelObject(); Component productCell = null; if (currentItemInMergedCell(item.getIndex())) { //my own implementation to check if the cell is part of an assymetric structure class FocussedProductFragment extends Fragment { public FocussedProductFragment(String id) { super(id, "focussedCell", ProductCatalogPanel.this); //matches fragment id : definition add(new Label("captionDefault", product.getName())); Component image = new StaticImageComponent("focussedImg", new Model(product.getAttributeValue(ProductDao.ATTRIB_PRODUCT_IMG_MAIN)) ); image.add(new SimpleAttributeModifier("class", "cellImgMain")); add(image); } } //Note: The fragment is to be used by the item; hence the main definition is subdues by setEnabled(false) grid.add(new FocussedProductFragment("focussedCellFragment").setVisible(false)); //NOTE : Line 1 item.add(new FocussedProductFragment("product")); //NOTE : Line 2 } else { item.add(<thumbnail image>); //Pseudo code line : to keep code short } //end-if .... } //end-populateItem ... } //end-createGrid //NOTE : Line 1 defines the fragment. But I cant have that cell appear twice so I setVisible(false) //NOTE : Line 2 is what is the markup that is used inside the Grid markup; so that is displayed. If I dont put line One, wicket cries that I have not defined the Fragment in my code. Is this elegant? I could not see any examples of fragments being used in repeated views. It works, but am always looking for cleaner more elegant code. ..Also, if my thoughts are conceptually on the correct line. criticism appreciated; if you got so far into reading this ...a BIG THANKS :) -Arjun -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Fragments-in-Loops-Grid-Views-tp3041253p3041253.html Sent from the Users forum mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
