View Javadoc
1   /**
2    * Copyright 2005-2016 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.uif.view;
17  
18  import java.util.List;
19  
20  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
21  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
22  import org.kuali.rice.krad.uif.component.Component;
23  import org.kuali.rice.krad.uif.element.Iframe;
24  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
25  import org.kuali.rice.krad.uif.util.ComponentFactory;
26  import org.kuali.rice.krad.uif.util.LifecycleElement;
27  import org.kuali.rice.krad.uif.util.UrlInfo;
28  
29  /**
30   * IframeView is a View component that shows another website's content in an iframe.
31   *
32   * <p>This View will always have one page itself and will always contain an iframe component.  The location
33   * property allows ease of setting the url for the iframe.  If the site being shown in the iframe is a KRAD View
34   * itself, the default bean for this class will attempt to pass a url parameter notifying the View that it is being
35   * shown in an iframe; this can be used in SpringEL to invoke special logic (such as not rendering some components,
36   * like the app header)</p>
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  @BeanTag(name = "iframeView", parent = "Uif-IframeView")
41  public class IframeView extends FormView {
42      private UrlInfo location;
43      private Iframe iframe;
44  
45      /**
46       * Forces this view to be only one page, and sets the iframe as one of its items
47       *
48       * {@inheritDoc}
49       */
50      @Override
51      public void performInitialization(Object model) {
52          super.performInitialization(model);
53  
54          super.setSinglePageView(true);
55  
56          List<Component> modifiedItems = (List<Component>) this.getPage().getItems();
57          modifiedItems.add(iframe);
58          this.getPage().setItems(modifiedItems);
59      }
60  
61      /**
62       * Evaluates expressions that may appear in location properties and sets the source of iframe automatically
63       *
64       * {@inheritDoc}
65       */
66      @Override
67      public void performApplyModel(Object model, LifecycleElement parent) {
68          super.performApplyModel(model, parent);
69  
70          if (location != null) {
71              ViewLifecycle.getExpressionEvaluator().populatePropertyExpressionsFromGraph(location, false);
72              ViewLifecycle.getExpressionEvaluator().evaluateExpressionsOnConfigurable(this, location, this.getContext());
73  
74              iframe.setSource(location.getHref());
75          }
76      }
77  
78      /**
79       * Get the url object representing the location
80       *
81       * @return the url location object
82       */
83      @BeanTagAttribute
84      public UrlInfo getLocation() {
85          return location;
86      }
87  
88      /**
89       * @see org.kuali.rice.krad.uif.view.IframeView#getLocation()
90       */
91      public void setLocation(UrlInfo location) {
92          this.location = location;
93      }
94  
95      /**
96       * @see org.kuali.rice.krad.uif.util.UrlInfo#getHref()
97       */
98      @BeanTagAttribute
99      public String getHref() {
100         if (this.location != null) {
101             return this.location.getHref();
102         }
103 
104         return null;
105     }
106 
107     /**
108      * @see IframeView#getHref()
109      */
110     public void setHref(String href) {
111         if (this.location == null) {
112             this.location = ComponentFactory.getUrlInfo();
113         }
114 
115         this.location.setHref(href);
116     }
117 
118     /**
119      * The iframe component to be used as the content of this view, nothing needs to be set on this directly if
120      * using the default bean for this View
121      *
122      * @return the iframe component
123      */
124     @BeanTagAttribute
125     public Iframe getIframe() {
126         return iframe;
127     }
128 
129     /**
130      * @see org.kuali.rice.krad.uif.view.IframeView#getIframe()
131      */
132     public void setIframe(Iframe iframe) {
133         this.iframe = iframe;
134     }
135 }