I don't have the habit to exend from Form, since I don't need to put logic there (I put it in my submitLinks/buttons)
On Thu, Dec 17, 2009 at 2:45 PM, Pieter Degraeuwe < pieter.degrae...@systemworks.be> wrote: > Use the onSubmit(AjaxRequestTarget target) of your AjaxSubmitLink instead > of your form. > (Note that if you make use of FeedbackPanel, youd should also override the > onError() method of that ajaxlink to 'refresh' your feedback panel) > > > > > On Thu, Dec 17, 2009 at 2:14 PM, marioosh.net <marioosh....@gmail.com>wrote: > >> >> >> Pieter Degraeuwe wrote: >> > >> > There are several ways how you can do this... >> > >> > To encourage losely coupled components folowing is in my opinion the >> best >> > solution.. >> > >> > Work with a callback mechanism. let's say you define a callback >> interface >> > SaveCallback with a method onSaved(AjaxRequestTarget target). >> > The component that uses you panel/form, can pass such a callback to >> define >> > de 'code' that needs to be executedn once the Link is saved. >> > >> > class MyPage { >> > >> > public MyPage() { >> > //construct panels.... >> > final Panel otherPanel = new ..... >> > otherPanel.setOutputMarkupId(true); //make it possible to refresh >> > this >> > panel via ajax >> > add(otherPanel); >> > >> > add(new NewLinkPanel("newLinkPanel",new SaveCallback() { >> > >> > onSaved(AjaxRequestTarget target) { >> > target.addComponent(otherPanel);//refresh other panel >> > } >> > }); >> > } >> > } >> > >> >> I did code like below, but i don't know how in onSubmit() method get >> AjaxRequestTarget object. >> >> // callback interface >> public interface AddLinkCallback { >> public void onAdd(AjaxRequestTarget target); >> } >> >> // main page with panels >> public class Base extends WebPage { >> public Base() { >> >> final ContentPanel contentPanel = new >> ContentPanel("content"); >> contentPanel.setOutputMarkupId(true); // can be updated by >> ajax >> NewLinkPanel linkPanel = new NewLinkPanel("newlink", new >> AddLinkCallback() { >> @Override >> public void onAdd(AjaxRequestTarget target) { >> // TODO Auto-generated method stub >> target.addComponent(contentPanel);//refresh other >> panel >> } >> }); >> } >> } >> >> // control panel (add button) >> public class NewLinkPanel extends Panel { >> public NewLinkPanel(String id, AddLinkCallback callback) { >> super(id); >> add(new LinkForm("linkform", callback)); >> } >> } >> class LinkForm extends Form { >> private AddLinkCallback callback; >> public LinkForm(String id, AddLinkCallback callback) { >> super(id); >> this.callback = callback; >> >> Link link = new Link(); >> this.setModel(new Model(link)); >> add(new TextField("name", new PropertyModel(link, >> "name"))); >> add(new TextField("address",new PropertyModel(link, >> "address"))); >> add(new AjaxSubmitLink("ok"){ >> @Override >> protected void onSubmit(AjaxRequestTarget target, >> Form form) {} >> }); >> } >> >> @Override >> protected void onSubmit() { >> System.out.println("ok"); >> Link l = (Link)this.getModelObject(); >> new LinkDAO().save(l); >> >> callback.onAdd(target ????); // >> ??????????????????????????? >> } >> } >> >> -- >> View this message in context: >> http://old.nabble.com/Accessing-Page-components-tp26824375p26827804.html >> Sent from the Wicket - User mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org >> For additional commands, e-mail: users-h...@wicket.apache.org >> >> > > > -- > Pieter Degraeuwe > Systemworks bvba > Belgiƫlaan 61 > 9070 Destelbergen > GSM: +32 (0)485/68.60.85 > Email: pieter.degrae...@systemworks.be > visit us at http://www.systemworks.be > -- Pieter Degraeuwe Systemworks bvba Belgiƫlaan 61 9070 Destelbergen GSM: +32 (0)485/68.60.85 Email: pieter.degrae...@systemworks.be visit us at http://www.systemworks.be