01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.examples.velocity;
18:
19: import java.util.HashMap;
20: import java.util.List;
21: import java.util.Map;
22:
23: import org.apache.wicket.PageParameters;
24: import org.apache.wicket.examples.WicketExamplePage;
25: import org.apache.wicket.markup.html.basic.Label;
26: import org.apache.wicket.markup.html.form.TextField;
27: import org.apache.wicket.model.Model;
28: import org.apache.wicket.model.ResourceModel;
29: import org.apache.wicket.util.resource.IStringResourceStream;
30: import org.apache.wicket.util.resource.PackageResourceStream;
31: import org.apache.wicket.velocity.markup.html.VelocityPanel;
32:
33: /**
34: * Template example page.
35: *
36: * @author <a href="mailto:jbq@apache.org">Jean-Baptiste Quenot</a>
37: */
38: public class DynamicPage extends WicketExamplePage {
39: /**
40: * Constructor
41: *
42: * @param parameters
43: * Page parameters
44: */
45: public DynamicPage(final PageParameters parameters) {
46: final IStringResourceStream template = new PackageResourceStream(
47: DynamicPage.class, "fields.vm");
48:
49: Map<String, List<Field>> map = new HashMap<String, List<Field>>();
50: List<Field> fields = VelocityTemplateApplication.getFields();
51: map.put("fields", fields);
52:
53: VelocityPanel panel;
54: add(panel = new VelocityPanel("templatePanel", Model
55: .valueOf(map)) {
56: @Override
57: protected IStringResourceStream getTemplateResource() {
58: return template;
59: }
60:
61: @Override
62: protected boolean parseGeneratedMarkup() {
63: return true;
64: }
65: });
66: for (Field field : fields) {
67: panel.add(new TextField(field.getFieldName()));
68: }
69: }
70: }
|