public DiscountsPage() { /* Section 9.1 */ RefreshingView discountsView = new RefreshingView("list") { private List<Discount> discounts; @Override protected Iterator getItemModels() { if (discounts == null) { discounts = DataBase.getInstance().listDiscounts(); } return new ModelIteratorAdapter(discounts.iterator()) { @Override protected IModel model(Object object) { return EqualsDecorator.decorate(new CompoundPropertyModel((Discount) object)); } }; } @Override protected void populateItem(Item item) { item.add(new Label("cheese.name")); item.add(new PercentageField("discount")); item.add(new RequiredTextField("description")); item.add(new DateField("from")); item.add(new DateField("until")); final Discount discount = (Discount) item.getModelObject(); final Link removeLink = new Link("remove") { @Override public void onClick() { DataBase.getInstance().remove(discount); } }; item.add(removeLink); removeLink.add( new Image( "icon", new ResourceReference(DiscountsEditList.class, "remove_icon.gif"))); removeLink.add( new SimpleAttributeModifier( "onclick", "if(!confirm('remove discount for " + discount.getCheese().getName() + " ?')) return false;")); } }; discountsView.setItemReuseStrategy(ReuseIfModelsEqualStrategy.getInstance()); add(discountsView); }
@Override public void onAfterRender(Component component) { if (component instanceof RefreshingView<?>) { // Nettoyage des metadonnées ajoutées dans onBeforeRender RefreshingView<?> form = (RefreshingView<?>) component; form.visitChildren( FormComponent.class, new IVisitor<FormComponent<?>, Void>() { @Override public void component(FormComponent<?> formComponent, IVisit<Void> visit) { formComponent.setMetaData(HAS_ERROR, null); } }); } }
@Override public void onBeforeRender(Component component) { if (component instanceof RefreshingView<?>) { RefreshingView<?> form = (RefreshingView<?>) component; form.visitChildren( FormComponent.class, new IVisitor<FormComponent<?>, Void>() { @Override public void component(FormComponent<?> formComponent, IVisit<Void> visit) { if (hasError(formComponent)) { formComponent.setMetaData(HAS_ERROR, HAS_ERROR); } } }); } }
@Override protected void onBeforeRender() { cachedPageCount = -1; super.onBeforeRender(); }
/** Cleanup */ @Override protected void onDetach() { super.onDetach(); queryResult = null; }