001 /*
002 * Apache License
003 * Version 2.0, January 2004
004 * http://www.apache.org/licenses/
005 *
006 * Copyright 2008-2010 by chenillekit.org
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 */
014
015 package org.chenillekit.tapestry.core.mixins;
016
017 import org.apache.tapestry5.BindingConstants;
018 import org.apache.tapestry5.ClientElement;
019 import org.apache.tapestry5.MarkupWriter;
020 import org.apache.tapestry5.annotations.Environmental;
021 import org.apache.tapestry5.annotations.Import;
022 import org.apache.tapestry5.annotations.InjectContainer;
023 import org.apache.tapestry5.annotations.Parameter;
024 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
025
026 /**
027 * This mixin allows a user to more easily enter fixed width input where you would like them to enter the data in a
028 * certain format (dates,phone numbers, etc).
029 * <p/>
030 * It has been tested on Internet Explorer 6/7, Firefox 1.5/2/3, Safari, Opera, and Chrome.
031 * A mask is defined by a format made up of mask literals and mask definitions.
032 * Any character not in the definitions list below is considered a mask literal.
033 * Mask literals will be automatically entered for the user as they type and will
034 * not be able to be removed by the user. The following mask definitions are predefined:
035 * <p/>
036 * <ul>
037 * <li>a - Represents an alpha character (A-Z,a-z)</li>
038 * <li>9 - Represents a numeric character (0-9)</li>
039 * <li>* - Represents an alphanumeric character (A-Z,a-z,0-9)</li>
040 * </ul>
041 *
042 * @version $Id: MaskedInput.java 674 2010-07-29 12:47:25Z homburgs $
043 */
044 @Import(library = {"prototype-maskedinput.js"})
045 public class MaskedInput
046 {
047 @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL, allowNull = false)
048 private String mask;
049
050 @InjectContainer
051 private ClientElement clientElement;
052
053 @Environmental
054 private JavaScriptSupport javascriptSupport;
055
056 /**
057 * Tapestry render phase method. End a tag here.
058 *
059 * @param writer the markup writer
060 */
061 void afterRender(MarkupWriter writer)
062 {
063 javascriptSupport.addScript("new MaskedInput('%s', '%s');", clientElement.getClientId(), mask);
064 }
065 }