001/** 002 * Copyright 2005-2018 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.uif.field; 017 018import java.util.List; 019 020import org.apache.commons.lang.StringUtils; 021import org.kuali.rice.krad.datadictionary.parse.BeanTag; 022import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute; 023import org.kuali.rice.krad.datadictionary.parse.BeanTags; 024import org.kuali.rice.krad.uif.UifConstants; 025import org.kuali.rice.krad.uif.component.Component; 026import org.kuali.rice.krad.uif.container.Group; 027import org.kuali.rice.krad.uif.lifecycle.ViewLifecycleRestriction; 028import org.kuali.rice.krad.uif.util.LifecycleElement; 029 030/** 031 * Field that contains a nested <code>Group</code>. Can be used to group 032 * together fields by providing a group without header and footer, or simply to 033 * nest full groups. The items getter/setter provided is for convenience and 034 * will set the items <code>List</code> in the nested <code>Group</code> 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 */ 038@BeanTags({@BeanTag(name = "fieldGroup", parent = "Uif-FieldGroupBase"), 039 @BeanTag(name = "verticalFieldGroup", parent = "Uif-VerticalFieldGroup"), 040 @BeanTag(name = "horizontalFieldGroup", parent = "Uif-HorizontalFieldGroup")}) 041public class FieldGroup extends FieldBase { 042 private static final long serialVersionUID = -505654043702442196L; 043 044 private Group group; 045 046 public FieldGroup() { 047 super(); 048 } 049 050 /** 051 * The following initialization is performed: 052 * 053 * <ul> 054 * <li>Set the align on group if empty and the align has been set on the field</li> 055 * </ul> 056 * 057 * {@inheritDoc} 058 */ 059 @Override 060 public void performInitialization(Object model) { 061 super.performInitialization(model); 062 063 if (StringUtils.isNotBlank(getAlign()) && group != null) { 064 group.setAlign(getAlign()); 065 } 066 } 067 068 /** 069 * {@inheritDoc} 070 */ 071 @Override 072 public void afterEvaluateExpression() { 073 super.afterEvaluateExpression(); 074 075 if (group != null) { 076 group.setReadOnly(getReadOnly()); 077 } 078 } 079 080 @Override 081 public void performFinalize(Object model, LifecycleElement parent) { 082 super.performFinalize(model, parent); 083 084 this.addDataAttribute(UifConstants.DataAttributes.PARENT, parent.getId()); 085 if (group != null) { 086 this.addDataAttribute(UifConstants.DataAttributes.GROUP, group.getId()); 087 } 088 089 setNestedComponentIdAndSuffix(getFieldLabel(), UifConstants.IdSuffixes.LABEL); 090 091 if (this.getFieldLabel() != null) { 092 this.getFieldLabel().setLabelForComponentId(this.getId() + UifConstants.IdSuffixes.FIELDSET); 093 } 094 } 095 096 /** 097 * <code>Group</code> instance that is contained within in the field 098 * 099 * @return Group instance 100 */ 101 @BeanTagAttribute(type = BeanTagAttribute.AttributeType.DIRECTORBYTYPE) 102 public Group getGroup() { 103 return this.group; 104 } 105 106 /** 107 * Setter for the field's nested group 108 * 109 * @param group 110 */ 111 public void setGroup(Group group) { 112 this.group = group; 113 } 114 115 /** 116 * List of <code>Component</code> instances contained in the nested group 117 * 118 * <p> 119 * Convenience method for configuration to get the items List from the 120 * field's nested group 121 * </p> 122 * 123 * @return List<? extends Component> items 124 */ 125 @ViewLifecycleRestriction 126 @BeanTagAttribute 127 public List<? extends Component> getItems() { 128 if (group != null) { 129 return group.getItems(); 130 } 131 132 return null; 133 } 134 135 /** 136 * Setter for the field's nested group items 137 * 138 * <p> 139 * Convenience method for configuration to set the items List for the 140 * field's nested group 141 * </p> 142 * 143 * @param items 144 */ 145 public void setItems(List<? extends Component> items) { 146 if (group != null) { 147 group.setItems(items); 148 } 149 } 150}