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: [email protected]
For additional commands, e-mail: [email protected]