View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.renderkit;
21  
22  import org.apache.myfaces.tobago.component.Attributes;
23  
24  import javax.faces.component.UIComponent;
25  import javax.faces.component.UIInput;
26  import javax.faces.context.FacesContext;
27  
28  public class HtmlUtils {
29  
30    public static final String LAYOUT_ATTRIBUTE_PREFIX = "layout.";
31    public static final String CHAR_NON_BEAKING_SPACE = "\u00a0";
32  
33    public static String generateAttribute(String name, Object value) {
34      String stringValue;
35      if (value == null) {
36        stringValue = null;
37      } else if (value instanceof String) {
38        stringValue = (String) value;
39      } else {
40        stringValue = value.toString();
41      }
42      return (stringValue != null && stringValue.length() > 0)
43          ? name + "=\"" + value + "\""
44          : "";
45    }
46  
47    public static String appendAttribute(UIComponent component, String name,
48        String appendValue) {
49      Object attribute = component.getAttributes().get(name);
50      return attribute != null
51          ? attribute.toString() + " " + appendValue : appendValue;
52    }
53  
54    public static String generateOnchange(UIInput component,
55        FacesContext facesContext) {
56  
57      /*Validator[] validators = component.getValidators();
58      for (int i = 0; i < validators.length; i++) {
59        if (validators[i] instanceof LongRangeValidator) {
60          String functionCall = "validateLongRange('"
61              + component.getClientId(facesContext) + "')";
62          if (LOG.isDebugEnabled()) {
63            LOG.debug("validator functionCall: " + functionCall);
64          }
65          buffer.append(functionCall);
66        } else {
67          buffer.append("true");
68        }
69        if (i + 1 < validators.length) { // is not last
70          buffer.append(" && ");
71        }
72      } */
73  
74      Object onchange = component.getAttributes().get(Attributes.ONCHANGE);
75      if (onchange != null) {
76        return onchange.toString();
77      }
78      return null;
79    }
80  
81  }