View Javadoc

1   // Copyright 2006 Daniel Gredler
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   //     http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package net.sf.beanform;
16  
17  import static net.sf.beanform.BeanFormComponent.BINDING_OVERRIDE_SEPARATOR;
18  
19  import org.apache.hivemind.util.Defense;
20  import org.apache.tapestry.IBinding;
21  import org.apache.tapestry.components.Any;
22  
23  /***
24   * A specialized {@link Any} component that expects to be contained by a {@link BeanForm}
25   * instance and which cannot inherit informal bindings containing the
26   * {@link BeanFormComponent#BINDING_OVERRIDE_SEPARATOR} separator.
27   *
28   * Such bindings are meant to indicate that a specific property's input field should
29   * have a binding overriden with the value specified, and are not meant to be written
30   * to the final HTML.
31   *
32   * @author Daniel Gredler
33   */
34  public abstract class InformalFilterAny extends Any {
35  
36      @Override
37      public void setBinding( String name, IBinding binding ) {
38          Defense.notNull( name, "name" );
39          Defense.notNull( binding, "binding" );
40          boolean formal = ( this.getSpecification().getParameter( name ) != null );
41          boolean override = ( name.contains( BINDING_OVERRIDE_SEPARATOR ) );
42          if( formal || ! override ) {
43              super.setBinding( name, binding );
44          }
45      }
46  
47  }