01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package info.jtrac.wicket.yui;
18:
19: import org.apache.wicket.Component;
20: import org.apache.wicket.ajax.AjaxRequestTarget;
21: import org.apache.wicket.ajax.markup.html.form.AjaxSubmitButton;
22: import org.apache.wicket.markup.html.form.Form;
23: import org.apache.wicket.markup.html.form.TextField;
24: import org.apache.wicket.markup.html.panel.FeedbackPanel;
25: import org.apache.wicket.markup.html.panel.Panel;
26: import org.apache.wicket.model.CompoundPropertyModel;
27:
28: /**
29: * test panel
30: */
31: public class TestPanel extends Panel {
32:
33: private Component nameField;
34:
35: public String getFocusScript() {
36: return "document.getElementById('" + nameField.getMarkupId()
37: + "').focus();";
38: }
39:
40: public TestPanel(String id) {
41: super (id);
42: add(new TestForm("form"));
43: }
44:
45: /**
46: * wicket form
47: */
48: private class TestForm extends Form {
49:
50: private String name;
51: private String description;
52:
53: public String getName() {
54: return name;
55: }
56:
57: public void setName(String name) {
58: this .name = name;
59: }
60:
61: public String getDescription() {
62: return description;
63: }
64:
65: public void setDescription(String description) {
66: this .description = description;
67: }
68:
69: public TestForm(String id) {
70: super (id);
71: setOutputMarkupId(true);
72: final FeedbackPanel feedback = new FeedbackPanel("feedback");
73: feedback.setOutputMarkupId(true);
74: add(feedback);
75: setModel(new CompoundPropertyModel(this ));
76: nameField = new TextField("name").setRequired(true)
77: .setOutputMarkupId(true);
78: add(nameField);
79: add(new TextField("description"));
80: add(new AjaxSubmitButton("submit", this ) {
81: @Override
82: protected void onError(AjaxRequestTarget target,
83: Form form) {
84: target.addComponent(feedback);
85: target.appendJavascript(getFocusScript());
86: }
87:
88: protected void onSubmit(AjaxRequestTarget target,
89: Form form) {
90: setResponsePage(new TestPage2(name, description));
91: }
92: });
93: }
94:
95: }
96:
97: }
|