001 package org.apache.myfaces.tobago.renderkit.html.example.standard.tag;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements. See the NOTICE file distributed with
006 * this work for additional information regarding copyright ownership.
007 * The ASF licenses this file to You under the Apache License, Version 2.0
008 * (the "License"); you may not use this file except in compliance with
009 * the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020 import org.apache.myfaces.tobago.component.UIInput;
021 import org.apache.myfaces.tobago.component.UIInputBase;
022 import org.apache.myfaces.tobago.renderkit.html.util.HtmlRendererUtil;
023
024 import javax.faces.component.UIComponent;
025 import javax.faces.context.FacesContext;
026 import java.io.IOException;
027 import java.util.Arrays;
028 import java.util.List;
029
030 /**
031 * Simple example for dynamic markups.
032 * <p>
033 * The markup 'changeaware' tracks changes
034 * of an input field and applies the style class 'example-changed' if the
035 * current value differs from the original one.
036 * </p><p>
037 * The markup 'blink' highlights the input field with the markup related
038 * style class 'tobago-in-markup-blink'. This class is removed after a
039 * certain amount time, which is specified in the Blinker JavaScript object
040 * in tobago.js.
041 * </p>
042 *
043 */
044 public class InRenderer extends org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.InRenderer{
045
046 @Override
047 protected void applyExtraStyle(FacesContext facesContext, UIInputBase input, String currentValue) {
048
049 }
050
051 @Override
052 public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
053 super.encodeEnd(facesContext, component);
054
055 UIInput input = (UIInput) component;
056 List<String> markup = Arrays.asList(input.getMarkup());
057 if (markup.contains("changeaware")) {
058 String id = input.getClientId(facesContext);
059 final String[] cmds = {
060 "new Example.ChangeAware('" + id + "');"
061 };
062 HtmlRendererUtil.writeScriptLoader(facesContext, null, cmds);
063 }
064 if (markup.contains("blink")) {
065 String id = input.getClientId(facesContext);
066 final String[] cmds = {
067 "new Example.Blinker('" + id + "');"
068 };
069 HtmlRendererUtil.writeScriptLoader(facesContext, null, cmds);
070 }
071 }
072
073 }