Author: ehillenius Date: Mon May 7 08:11:30 2007 New Revision: 535892 URL: http://svn.apache.org/viewvc?view=rev&rev=535892 Log: example for wicket-velocity
Added: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/Person.java incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.html incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.java incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/VelocityTemplateApplication.java Added: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/Person.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/Person.java?view=auto&rev=535892 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/Person.java (added) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/Person.java Mon May 7 08:11:30 2007 @@ -0,0 +1,90 @@ +/* + * 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.examples.velocity; + +import java.io.Serializable; + +/** + * Simple person object. + */ +public final class Person implements Serializable +{ + private String firstName; + + private String lastName; + + /** + * Construct. + */ + public Person() + { + } + + /** + * Construct. + * + * @param firstName + * @param lastName + */ + public Person(String firstName, String lastName) + { + this.firstName = firstName; + this.lastName = lastName; + } + + /** + * Gets the firstName. + * + * @return firstName + */ + public final String getFirstName() + { + return firstName; + } + + /** + * Gets the lastName. + * + * @return lastName + */ + public final String getLastName() + { + return lastName; + } + + /** + * Sets the firstName. + * + * @param firstName + * firstName + */ + public final void setFirstName(String firstName) + { + this.firstName = firstName; + } + + /** + * Sets the lastName. + * + * @param lastName + * lastName + */ + public final void setLastName(String lastName) + { + this.lastName = lastName; + } +} \ No newline at end of file Added: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.html URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.html?view=auto&rev=535892 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.html (added) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.html Mon May 7 08:11:30 2007 @@ -0,0 +1,58 @@ +<html> +<head> + <title>Wicket Contrib Examples - Template Page</title> + <link rel="stylesheet" type="text/css" href="style.css"/> +</head> +<body> + + <span wicket:id="mainNavigation"/> + + <div id="explain"> + <h3>Velocity Template Component</h3> + <p> + The VelocityPanel is usefull for CMS like functionality, where you want + to enable users to do basic scripting in predefined areas of your web + application. Read more about the + <a href="http://jakarta.apache.org/velocity/">velocity</a> language + <a href="http://jakarta.apache.org/velocity/user-guide.html">here</a>. + </p> + </div> + +<table cellpadding="5px"> + <tr> + <td valign="top" height="100%"> + + <div id="templateInputBox"> + <form wicket:id="templateForm"> + <fieldset> + <legend><a target="#" href="http://jakarta.apache.org/velocity/">velocity</a> template input</legend> + + <textarea wicket:id="templateInput" rows="16" cols="36">Template input comes here</textarea> + + <div id="templateUpdateButton"> + <input type="submit" value="update"/> + </div> + </fieldset> + </form> + </div> + + </td> + <td valign="top" height="100%"> + + <div id="templateOutputBox"> + <fieldset> + <legend>output</legend> + <span wicket:id="templatePanel">Template output will be put here</span> + </fieldset> + </div> + + </td> + </tr> +</table> + + <div> + <span wicket:id="feedback"/> + </div> + +</body> +</html> Added: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.java?view=auto&rev=535892 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.java (added) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/TemplatePage.java Mon May 7 08:11:30 2007 @@ -0,0 +1,125 @@ +/* + * 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.examples.velocity; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.wicket.PageParameters; +import org.apache.wicket.examples.WicketExamplePage; +import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.TextArea; +import org.apache.wicket.markup.html.panel.FeedbackPanel; +import org.apache.wicket.model.Model; +import org.apache.wicket.model.PropertyModel; +import org.apache.wicket.util.resource.StringBufferResourceStream; +import org.apache.wicket.velocity.markup.html.VelocityPanel; + +/** + * Template example page. + * + * @author Eelco Hillenius + */ +public class TemplatePage extends WicketExamplePage +{ + /** + * Form for changing the template contents. + */ + private final class TemplateForm extends Form + { + private TextArea templateTextArea; + + /** + * Construct. + * + * @param name + * component name + */ + public TemplateForm(String name) + { + super(name); + add(templateTextArea = new TextArea("templateInput", new PropertyModel(new Model( + TemplatePage.this), "template"))); + } + + /** + * @see org.apache.wicket.markup.html.form.Form#onSubmit() + */ + protected void onSubmit() + { + } + } + + /** the current template contents. */ + private StringBufferResourceStream template = new StringBufferResourceStream(); + /** context to be used by the template. */ + private final Model templateContext; + + { + template.append("<fieldset>\n"); + template.append(" <legend>persons</legend>\n"); + template.append(" <ul>\n"); + template.append(" #foreach( $person in $persons )\n"); + template.append(" <li>\n"); + template.append(" ${person.lastName},\n"); + template.append(" ${person.firstName}\n"); + template.append(" </li>\n"); + template.append(" #end\n"); + template.append(" </ul>\n"); + template.append("</fieldset>\n"); + } + + /** + * Constructor + * + * @param parameters + * Page parameters + */ + public TemplatePage(final PageParameters parameters) + { + Map<String, List<Person>> map = new HashMap<String, List<Person>>(); + map.put("persons", VelocityTemplateApplication.getPersons()); + templateContext = Model.valueOf(map); + + add(new TemplateForm("templateForm")); + add(new VelocityPanel("templatePanel", template, templateContext)); + add(new FeedbackPanel("feedback")); + } + + /** + * Gets the current template contents. + * + * @return the current template contents + */ + public final String getTemplate() + { + return template.asString(); + } + + /** + * Sets the current template contents. + * + * @param template + * the current template contents + */ + public final void setTemplate(String template) + { + this.template.clear(); + this.template.append(template); + } +} \ No newline at end of file Added: incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/VelocityTemplateApplication.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/VelocityTemplateApplication.java?view=auto&rev=535892 ============================================================================== --- incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/VelocityTemplateApplication.java (added) +++ incubator/wicket/trunk/jdk-1.5/wicket-examples/src/main/java/org/apache/wicket/examples/velocity/VelocityTemplateApplication.java Mon May 7 08:11:30 2007 @@ -0,0 +1,90 @@ +/* + * 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.examples.velocity; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.velocity.app.Velocity; +import org.apache.wicket.Page; +import org.apache.wicket.WicketRuntimeException; +import org.apache.wicket.protocol.http.WebApplication; +import org.apache.wicket.util.time.Duration; + +/** + * Application class for velocity template example. + * + * @author Eelco Hillenius + */ +public class VelocityTemplateApplication extends WebApplication +{ + /** simple persons db. */ + private static List<Person> persons = new ArrayList<Person>(); + static + { + persons.add(new Person("Joe", "Down")); + persons.add(new Person("Fritz", "Frizel")); + persons.add(new Person("Flip", "Vlieger")); + persons.add(new Person("George", "Forrest")); + persons.add(new Person("Sue", "Hazel")); + persons.add(new Person("Bush", "Gump")); + } + + /** + * Gets the dummy persons database. + * + * @return the dummy persons database + */ + public static List<Person> getPersons() + { + return persons; + } + + /** + * Constructor. + */ + public VelocityTemplateApplication() + { + } + + /** + * @return class + */ + public Class< ? extends Page> getHomePage() + { + return TemplatePage.class; + } + + /** + * @see org.apache.wicket.protocol.http.WebApplication#init() + */ + @Override + protected void init() + { + getResourceSettings().setResourcePollFrequency(Duration.ONE_SECOND); + + // initialize velocity + try + { + Velocity.init(); + } + catch (Exception e) + { + throw new WicketRuntimeException(e); + } + } +}