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.container;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
23  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
24  import org.kuali.rice.krad.datadictionary.parse.BeanTags;
25  import org.kuali.rice.krad.datadictionary.validator.ValidationTrace;
26  import org.kuali.rice.krad.uif.UifConstants;
27  import org.kuali.rice.krad.uif.component.Component;
28  import org.kuali.rice.krad.uif.element.Header;
29  import org.kuali.rice.krad.uif.lifecycle.ViewLifecycle;
30  import org.kuali.rice.krad.uif.element.BreadcrumbItem;
31  import org.kuali.rice.krad.uif.util.LifecycleElement;
32  import org.kuali.rice.krad.uif.element.PageBreadcrumbOptions;
33  import org.kuali.rice.krad.uif.view.FormView;
34  import org.kuali.rice.krad.uif.view.View;
35  import org.kuali.rice.krad.web.form.UifFormBase;
36  
37  /**
38   * A PageGroup represents a page of a View.
39   *
40   * <p>
41   * PageGroups should only be used with a View component.  The contain the main content that will be seen by the
42   * user using the View.  Like all other groups, PageGroup can contain items, headers and footers.  Pages also
43   * have their own BreadcrumbItem.
44   * </p>
45   *
46   * @author Kuali Rice Team (rice.collab@kuali.org)
47   */
48  @BeanTags({@BeanTag(name = "page", parent = "Uif-Page"),
49          @BeanTag(name = "documentPage", parent = "Uif-DocumentPage"),
50          @BeanTag(name = "inquiryPage", parent = "Uif-InquiryPage"),
51          @BeanTag(name = "maintenancePage", parent = "Uif-MaintenancePage")})
52  public class PageGroupBase extends GroupBase implements PageGroup {
53      private static final long serialVersionUID = 7571981300587270274L;
54  
55      private boolean autoFocus = false;
56  
57      private PageBreadcrumbOptions breadcrumbOptions;
58      private BreadcrumbItem breadcrumbItem;
59      private boolean stickyFooter;
60      private String formPostUrl;
61  
62  
63      /**
64       * {@inheritDoc}
65       */
66      @Override
67      public void performInitialization(Object model) {
68          super.performInitialization(model);
69  
70          //check to see if one of the items is a page, if so throw an exception
71          for (Component item : this.getItems()) {
72              if (item != null && item instanceof PageGroup) {
73                  throw new RuntimeException("The page with id='"
74                          + this.getId()
75                          + "' contains a page with id='"
76                          + item.getId()
77                          + "'.  Nesting a page within a page is not allowed since only one "
78                          + "page's content can be shown on the View "
79                          + "at a time.  This may have been caused by possible misuse of the singlePageView flag (when "
80                          + "this flag is true, items set on the View become items of the single page.  Instead use "
81                          + "the page property on the View to set the page being used).");
82              }
83          }
84  
85          breadcrumbOptions.setupBreadcrumbs(model);
86      }
87  
88      /**
89       * {@inheritDoc}
90       */
91      @Override
92      public void performFinalize(Object model, LifecycleElement parent) {
93          if (StringUtils.isBlank(this.getWrapperTag())) {
94              this.setWrapperTag(UifConstants.WrapperTags.MAIN);
95          }
96  
97          super.performFinalize(model, parent);
98  
99          UifFormBase formBase = (UifFormBase) model;
100 
101         // If AutoFocus then set the focus_id to FIRST field, unless focus_id is also specified
102         if (isAutoFocus() && StringUtils.isNotBlank(formBase.getFocusId())) {
103             this.addDataAttribute(UifConstants.ActionDataAttributes.FOCUS_ID, formBase.getFocusId());
104         } else if (isAutoFocus()) {
105             this.addDataAttribute(UifConstants.ActionDataAttributes.FOCUS_ID, UifConstants.Order.FIRST.name());
106         }
107 
108         // Add jumpToId as a data attribute
109         if (StringUtils.isNotBlank(formBase.getJumpToId())) {
110             this.addDataAttribute(UifConstants.ActionDataAttributes.JUMP_TO_ID, formBase.getJumpToId());
111         }
112 
113         // Add jumpToName as a data attribute
114         if (StringUtils.isNotBlank(formBase.getJumpToName())) {
115             this.addDataAttribute(UifConstants.ActionDataAttributes.JUMP_TO_NAME, formBase.getJumpToName());
116         }
117 
118         this.addDataAttribute(UifConstants.DataAttributes.ROLE, UifConstants.RoleTypes.PAGE);
119 
120         String prefixScript = "";
121         if (this.getOnDocumentReadyScript() != null) {
122             prefixScript = this.getOnDocumentReadyScript();
123         }
124 
125         View view = ViewLifecycle.getView();
126         if (view instanceof FormView && ((FormView) view).isValidateClientSide()) {
127             this.setOnDocumentReadyScript(prefixScript + "\nsetupPage(true);");
128         } else {
129             this.setOnDocumentReadyScript(prefixScript + "\nsetupPage(false);");
130         }
131 
132         breadcrumbOptions.finalizeBreadcrumbs(model, this, breadcrumbItem);
133     }
134 
135     /**
136      * {@inheritDoc}
137      */
138     @Override
139     public List<String> getAdditionalTemplates() {
140         List<String> additionalTemplates = super.getAdditionalTemplates();
141 
142         Header viewHeader = ViewLifecycle.getView().getHeader();
143         if (viewHeader != null) {
144             if (additionalTemplates.isEmpty()) {
145                 additionalTemplates = new ArrayList<String>();
146             }
147             additionalTemplates.add(viewHeader.getTemplate());
148         }
149 
150         return additionalTemplates;
151     }
152 
153     /**
154      * {@inheritDoc}
155      */
156     @Override
157     @BeanTagAttribute(name = "autoFocus")
158     public boolean isAutoFocus() {
159         return this.autoFocus;
160     }
161 
162     /**
163      * {@inheritDoc}
164      */
165     @Override
166     public void setAutoFocus(boolean autoFocus) {
167         this.autoFocus = autoFocus;
168     }
169 
170     /**
171      * {@inheritDoc}
172      */
173     @Override
174     @BeanTagAttribute
175     public PageBreadcrumbOptions getBreadcrumbOptions() {
176         return breadcrumbOptions;
177     }
178 
179     /**
180      * {@inheritDoc}
181      */
182     @Override
183     public void setBreadcrumbOptions(PageBreadcrumbOptions breadcrumbOptions) {
184         this.breadcrumbOptions = breadcrumbOptions;
185     }
186 
187     /**
188      * {@inheritDoc}
189      */
190     @Override
191     public List<BreadcrumbItem> getHomewardPathBreadcrumbs() {
192         return breadcrumbOptions == null ? null : breadcrumbOptions.getHomewardPathBreadcrumbs();
193     }
194 
195     /**
196      * {@inheritDoc}
197      */
198     @Override
199     public List<BreadcrumbItem> getPreViewBreadcrumbs() {
200         return breadcrumbOptions == null ? null : breadcrumbOptions.getPreViewBreadcrumbs();
201     }
202 
203     /**
204      * {@inheritDoc}
205      */
206     @Override
207     public List<BreadcrumbItem> getPrePageBreadcrumbs() {
208         return breadcrumbOptions == null ? null : breadcrumbOptions.getPrePageBreadcrumbs();
209     }
210 
211     /**
212      * {@inheritDoc}
213      */
214     @Override
215     public List<BreadcrumbItem> getBreadcrumbOverrides() {
216         return breadcrumbOptions == null ? null : breadcrumbOptions.getBreadcrumbOverrides();
217     }
218 
219     /**
220      * {@inheritDoc}
221      */
222     @Override
223     @BeanTagAttribute
224     public BreadcrumbItem getBreadcrumbItem() {
225         return breadcrumbItem;
226     }
227 
228     /**
229      * {@inheritDoc}
230      */
231     @Override
232     public void setBreadcrumbItem(BreadcrumbItem breadcrumbItem) {
233         this.breadcrumbItem = breadcrumbItem;
234     }
235 
236     /**
237      * {@inheritDoc}
238      */
239     @Override
240     @BeanTagAttribute
241     public boolean isStickyFooter() {
242         return stickyFooter;
243     }
244 
245     /**
246      * {@inheritDoc}
247      */
248     @Override
249     public void setStickyFooter(boolean stickyFooter) {
250         this.stickyFooter = stickyFooter;
251 
252         if (this.getFooter() != null) {
253             this.getFooter().addDataAttribute(UifConstants.DataAttributes.STICKY_FOOTER, Boolean.toString(
254                     stickyFooter));
255         }
256     }
257 
258     /**
259      * {@inheritDoc}
260      */
261     @Override
262     @BeanTagAttribute
263     public String getFormPostUrl() {
264         return formPostUrl;
265     }
266 
267     /**
268      * {@inheritDoc}
269      */
270     @Override
271     public void setFormPostUrl(String formPostUrl) {
272         this.formPostUrl = formPostUrl;
273     }
274 
275     /**
276      * {@inheritDoc}
277      */
278     @Override
279     public void completeValidation(ValidationTrace tracer) {
280         tracer.addBean(this);
281 
282         // Checks that no invalid items are present
283         for (int i = 0; i < getItems().size(); i++) {
284             if (PageGroup.class.isAssignableFrom(getItems().get(i).getClass())
285                     || TabNavigationGroup.class.isAssignableFrom(getItems().get(i).getClass())) {
286                 String currentValues[] = {"item(" + i + ").class =" + getItems().get(i).getClass()};
287                 tracer.createError("Items in PageGroup cannot be PageGroup or NaviagtionGroup", currentValues);
288             }
289         }
290 
291         super.completeValidation(tracer.getCopy());
292     }
293 
294 }