001 /*
002 * Databinder: a simple bridge from Wicket to Hibernate
003 * Copyright (C) 2006 Nathan Hamblen nathan@technically.us
004
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either
008 * version 2.1 of the License, or (at your option) any later version.
009 *
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013 * Lesser General Public License for more details.
014 *
015 * You should have received a copy of the GNU Lesser General Public
016 * License along with this library; if not, write to the Free Software
017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
018 */
019 package net.databinder.components;
020
021 import org.apache.wicket.behavior.HeaderContributor;
022 import org.apache.wicket.markup.html.resources.JavaScriptReference;
023
024 /**
025 * Component for a script (JavaScript) link. The stylesheet is expected to be named
026 * <ClassName>.js for the class specified in the constructor and be located in
027 * the same package as that class.
028 * @author Nathan Hamblen
029 */
030 public class ScriptLink extends JavaScriptReference {
031 private static String EXT = ".js";
032
033 /** Builds a ScriptLink based on the given class. */
034 public ScriptLink(String id, Class componentClass) {
035 super(id, componentClass, componentClass.getSimpleName() + EXT);
036 }
037
038 /**
039 * Get a [classname].js header contriubtor that can be added to a component without any reference in
040 * its markup. Useful for subclasses that do not have their own templates.
041 * @param componentClass javascript file should be in same package and have same base name
042 * @return contributor to add to component
043 */
044 public static HeaderContributor headerContributor(Class componentClass) {
045 return HeaderContributor.forJavaScript(
046 componentClass, componentClass.getSimpleName() + EXT);
047 }
048 }