I solved the problem. I was't putting target.addComponent. Just for
reference,here is how it looks now .
public final AjaxSubmitLink moveDownMasterChainLink(final String id,
final
ListItem<T> item, MasterChainListForm form)
{
return new AjaxSubmitLink(id)
{
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target,
Form<?> form) {
// TODO Auto-generated method stub
final int index =
getList().indexOf(item.getModelObject());
if (index != -1)
{
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);
MyListView.this.removeAll();
}
target.addComponent(form);
}
/**
* @see org.apache.wicket.Component#onBeforeRender()
*/
@Override
protected void onBeforeRender()
{
super.onBeforeRender();
//setAutoEnable(false);
if (getList().indexOf(item.getModelObject()) ==
(getList().size() - 1))
{
setEnabled(false);
}
}
};
}
wicketnewuser 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);
> MyListView.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);
> }
> }
> };
> }
>
> /**
>
>
>
--
View this message in context:
http://old.nabble.com/model-update-in-moveuplink-and-movedownlink-onclick-tp26249946p26259337.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]