📄 nestedformspage.java
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.wicket.markup.html.form;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.MarkupStream;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.validation.EqualInputValidator;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Gerolf Seitz
*/
public class NestedFormsPage extends WebPage
{
private static final long serialVersionUID = 1L;
static Logger logger = LoggerFactory.getLogger(NestedFormsPage.class);
private final FeedbackPanel feedback;
/**
* Construct.
*/
public NestedFormsPage()
{
feedback = new FeedbackPanel("feedback");
add(feedback.setOutputMarkupId(true));
Form outerForm = new NestableForm("outerForm");
add(outerForm.setOutputMarkupId(true));
Form middleForm = new NestableForm("middleForm");
outerForm.add(middleForm.setOutputMarkupId(true));
Form innerForm = new NestableForm("innerForm");
middleForm.add(innerForm.setOutputMarkupId(true));
}
public class NestableForm extends Form
{
private static final long serialVersionUID = 1L;
private final String first = "test";
private final String second = "test";
public boolean onSubmitCalled = false;
public boolean onErrorCalled = false;
public NestableForm(String id)
{
super(id);
setModel(new CompoundPropertyModel(this));
TextField firstField = new RequiredTextField("first");
TextField secondField = new TextField("second");
add(firstField);
add(secondField);
add(new EqualInputValidator(firstField, secondField));
add(new AjaxSubmitLink("ajaxSubmit", this)
{
private static final long serialVersionUID = 1L;
protected void onSubmit(AjaxRequestTarget target, Form form)
{
target.addComponent(feedback);
}
protected void onError(AjaxRequestTarget target, Form form)
{
target.addComponent(feedback);
}
});
add(new ToggleLink("toggle", this));
add(new SubmitLink("submit"));
}
protected void onSubmit()
{
super.onSubmit();
onSubmitCalled = true;
logger.info(getId() + ".onSubmit");
}
protected void onError()
{
super.onError();
onErrorCalled = true;
logger.info(getId() + ".onError");
}
}
private class ToggleLink extends Link
{
private static final long serialVersionUID = 1L;
private final Form form;
public ToggleLink(String id, Form form)
{
super(id);
this.form = form;
}
public void onClick()
{
form.setEnabled(!form.isEnabled());
form.info(form.getId() + ".isEnabled() == " + form.isEnabled());
}
protected void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
{
String state = form.isEnabled() ? "enabled" : "disabled";
replaceComponentTagBody(markupStream, openTag, "form is " + state);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -