View Javadoc

1   /**
2    * Copyright 2005-2012 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.krad.service.impl;
17  
18  import org.kuali.rice.krad.datadictionary.validation.ViewAttributeValueReader;
19  import org.kuali.rice.krad.datadictionary.validation.result.DictionaryValidationResult;
20  import org.kuali.rice.krad.service.DictionaryValidationService;
21  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22  import org.kuali.rice.krad.service.ViewValidationService;
23  import org.kuali.rice.krad.uif.view.View;
24  import org.kuali.rice.krad.uif.view.ViewModel;
25  
26  /**
27   * Implementation of Validation service for views, uses the same validation mechanisms as DictionaryValidationService
28   * but uses a different AttributeValueReader to get the correct information from InputFields - which
29   * include any AttributeDefinition defined attributes, if defined and not overriden
30   *
31   * @see ViewValidationService
32   */
33  public class ViewValidationServiceImpl implements ViewValidationService {
34  
35      protected DictionaryValidationService dictionaryValidationService;
36  
37      @Override
38      public DictionaryValidationResult validateView(ViewModel model) {
39          return validateView(model.getPostedView(), model);
40      }
41  
42      @Override
43      public DictionaryValidationResult validateView(View view, ViewModel model) {
44          return getDictionaryValidationService().validate(new ViewAttributeValueReader(view, model), true);
45      }
46  
47      public DictionaryValidationService getDictionaryValidationService() {
48          if (dictionaryValidationService == null) {
49              this.dictionaryValidationService = KRADServiceLocatorWeb.getDictionaryValidationService();
50          }
51          return dictionaryValidationService;
52      }
53  
54      public void setDictionaryValidationService(DictionaryValidationService dictionaryValidationService) {
55          this.dictionaryValidationService = dictionaryValidationService;
56      }
57  }