you have to use submitlinks for move up/down. -igor
On Sat, Nov 7, 2009 at 4:31 PM, Swarnim Ranjitkar <[email protected]> wrote: > > Is there anyway that you can update model before you move the item up or down > using moveuplink and movedownlink in listview. My goal is to save the input > data to the model so that I don't loose use input on the item before moving > the item. I did try to extend the ListView and added my own moveuplink and > downlink code called form's updateFormComponentModels() method but that > didn't really help. Does anyone have any idea how this can be done. > > LeadTransnodeChain lc = new LeadTransnodeChain(1, 2, 3, 4, 5, > LeadTransnodeChain.MODE.ASYNC); > masterChainList.add(lc); > masterChainList.add(new LeadTransnodeChain(11, 12, 13, 14, 15, > LeadTransnodeChain.MODE.SYNC)); > masterChainList.add(new LeadTransnodeChain(21, 22, 23, 24, 25, > LeadTransnodeChain.MODE.SYNC)); > > ListView propertiesList = new MyListView("masterChainList", > masterChainList) { > > �...@override > protected void populateItem(ListItem item) { > LeadTransnodeChain leadTransnodeChain = (LeadTransnodeChain) > item.getModelObject(); > > > item.add(new Label("masterChain", new > PropertyModel(leadTransnodeChain, "m_masterChainID"))); > item.add(new DropDownChoice("runAs", new > PropertyModel(leadTransnodeChain, "m_mode"), > Arrays.asList(LeadTransnodeChain.MODE.values()), new IChoiceRenderer() { > public Object getDisplayValue(Object mode) { > return ((LeadTransnodeChain.MODE) mode).toString(); > } > > public String getIdValue(Object obj, int index) { > return obj.toString(); > } > } > > )); > item.add(moveMyUpLink("moveUp", item, form)); > item.add(moveMyDownLink("moveDown", item, form)); > > > } > }; > add(new Button("submitButton")); > > propertiesList.setReuseItems(true); > add(propertiesList); > }public void updateComponentModels(){ > super.updateFormComponentModels(); > } > > > public abstract class MyListView<T> extends ListView<T> { > > ... > > protected abstract void populateItem(ListItem item) ; > > /** > * Returns a link that will move the given item "down" (towards the end) > in the listView. > * > * @param id > * Name of move-down link component to create > * @param item > * @return The link component > */ > public final Link<Void> moveMyDownLink(final String id, final ListItem<T> > item, final MasterChainListForm form) > { > return new Link<Void>(id) > { > private static final long serialVersionUID = 1L; > > /** > * @see org.apache.wicket.markup.html.link.Link#onClick() > */ > �...@override > public void onClick() > { > final int index = getList().indexOf(item.getModelObject()); > if (index != -1) > { > form.updateComponentModels(); > addStateChange(new Change() > { > private static final long serialVersionUID = 1L; > > final int oldIndex = index; > > �...@override > public void undo() > { > Collections.swap(getList(), oldIndex + 1, > oldIndex); > } > > }); > > // Swap list items and invalidate listView > Collections.swap(getList(), index, index + 1); > MasterChainListView.this.removeAll(); > } > } > > /** > * @see org.apache.wicket.Component#onBeforeRender() > */ > �...@override > protected void onBeforeRender() > { > super.onBeforeRender(); > setAutoEnable(false); > if (getList().indexOf(item.getModelObject()) == > (getList().size() - 1)) > { > setEnabled(false); > } > } > }; > } > > /** > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
