View Javadoc

1   /*
2    * Copyright 2007-2010 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kns.web.format;
17  
18  import java.util.Collection;
19  
20  import org.kuali.rice.kns.web.format.Formatter;
21  
22  /**
23   * Currently, in the {@link Formatter Formatter} class, array are formatted
24   * by returning the first item in the array.  This is not acceptable in some cases.
25   * 
26   * <p>
27   * One example is a struts multi-select dropdown.  In order for struts to correctly handle
28   * field highlighting struts expects an array.
29   * </p>
30   * 
31   * <p>
32   * This formatter does not handle {@code null} arrays or arrays with {@code null} items.
33   * This class may need to be modified to handle these conditions.
34   * </p>
35   */
36  public class ArrayFormatter extends Formatter {
37      
38      private static final long serialVersionUID = -2207993820610088716L;
39  
40      /*
41      public Object convertFromPresentationFormat(Object value) {
42          if (isEmptyValue(value))
43              return getNullObjectValue();
44  
45          Class type = value.getClass();
46          boolean isArray = true;
47          boolean isCollection = propertyType != null && Collection.class.isAssignableFrom(propertyType);
48  
49          String[] strings = isArray ? (String[]) value : new String[] { (String) value };
50  
51          return isArray ? convertToArray(strings) : convertToCollection(strings);
52      }
53      */
54      /**
55       * Returns the value passed in.
56       * 
57       * {@inheritDoc}
58       */
59      @Override
60      public Object formatObject(Object value) {
61          return value;
62      }
63  }