package org.apache.wicket.examples.compref;
import org.apache.wicket.examples.WicketExamplePage;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.OnEventHeaderItem;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
@link
@author
public class SubmitLinkPage extends WicketExamplePage
{
public SubmitLinkPage()
{
FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
add(feedbackPanel);
Form< ? > form = new Form("form")
{
@Override
public void renderHead(IHeaderResponse response)
{
super.renderHead(response);
response.render(OnEventHeaderItem.forComponent(this, "submit",
"return confirm('Do you really want to submit?')"));
}
};
add(form);
SubmitLink internal = new SubmitLink("internal")
{
@Override
protected boolean shouldTriggerJavaScriptSubmitEvent()
{
return false;
}
@Override
public void onSubmit()
{
info("internal onsubmit");
}
};
form.add(internal);
SubmitLink external = new SubmitLink("external", form)
{
@Override
public void onSubmit()
{
info("external onsubmit");
}
};
add(external);
}
@Override
protected void explain()
{
String html = "<form wicket:id=\"form\">\n"
+ "<a wicket:id=\"internal\">Internal SubmitLink</a>\n" + "</form>\n"
+ "<a wicket:id=\"external\">External SubmitLink</a>\n";
String code = " public SubmitLinkPage() {\n"
+ " // Add a FeedbackPanel for displaying our messages\n"
+ " FeedbackPanel feedbackPanel = new FeedbackPanel(\"feedback\");\n"
+ " add(feedbackPanel);\n"
+ "\n"
+ " // Add a form with 2 SubmitLinks that can be called\n"
+ " Form form = new Form(\"form\");\n"
+ " add(form);\n"
+ " SubmitLink internal = new SubmitLink(\"internal\");\n"
+ " form.add(internal);\n"
+ " SubmitLink external = new SubmitLink(\"external\", form);\n"
+ " add(external);\n"
+ " });\n" + " }";
add(new ExplainPanel(html, code));
}
}