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  package org.apache.myfaces.custom.dynaForm.metadata.impl.jsf;
20  
21  
22  import java.util.Iterator;
23  
24  import org.apache.myfaces.custom.dynaForm.component.dynaForm.DynaConfig;
25  import org.apache.myfaces.custom.dynaForm.component.dynaForm.DynaConfigs;
26  import org.apache.myfaces.custom.dynaForm.component.dynaForm.DynaForm;
27  import org.apache.myfaces.custom.dynaForm.metadata.Extractor;
28  import org.apache.myfaces.custom.dynaForm.metadata.MetaData;
29  
30  /***
31   * Extract metadata from jsf form.<br />
32   * This will read all facets with "ff_" name prefix but nothing will be configured.
33   * Its just there to collect which fields to show if in exclusiveFieldMode
34   */
35  public class JsfRequestFieldExtractor implements Extractor
36  {
37      public JsfRequestFieldExtractor()
38      {
39      }
40  
41      public void getMetaData(MetaData metaData, Object entity)
42      {
43          if (!(entity instanceof DynaForm))
44          {
45              throw new IllegalArgumentException("passed entity argument not a DynaForm: " + entity);
46          }
47          
48          create(metaData, (DynaForm) entity);
49      }
50  
51      /***
52       * create the metadata out of the dynaConfigs for the given component
53       */
54      @SuppressWarnings("unchecked")
55      protected void create(MetaData metaData, DynaForm dynaForm)
56      {
57          DynaConfigs formConfig = dynaForm.getFormConfigs();
58          if (formConfig == null)
59          {
60              return;
61          }
62          
63          Iterator<DynaConfig> entries = formConfig.iterator();
64          while (entries.hasNext())
65          {
66              DynaConfig dynaConfig = entries.next();
67              String name = dynaConfig.getFor();
68              if (name == null)
69              {
70                  throw new IllegalArgumentException("'for' in config tag required");
71              }
72              
73              if (metaData.processField(name))
74              {
75                  metaData.requestField(name);
76              }
77          }
78      }
79  }