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.web.form; 017 018 019import javax.servlet.http.HttpServletRequest; 020 021import org.apache.commons.lang.StringUtils; 022import org.apache.log4j.Logger; 023import org.kuali.rice.krad.inquiry.Inquirable; 024import org.kuali.rice.krad.uif.UifConstants.ViewType; 025import org.kuali.rice.krad.uif.view.InquiryView; 026import org.kuali.rice.krad.web.bind.RequestAccessible; 027 028/** 029 * Form class for <code>InquiryView</code> screens 030 * 031 * @author Kuali Rice Team (rice.collab@kuali.org) 032 */ 033public class InquiryForm extends UifFormBase { 034 private static final long serialVersionUID = 4733144086378429410L; 035 036 @RequestAccessible 037 private String dataObjectClassName; 038 private Object dataObject; 039 040 private boolean redirectedInquiry; 041 042 public InquiryForm() { 043 setViewTypeName(ViewType.INQUIRY); 044 045 redirectedInquiry = false; 046 } 047 048 /** 049 * Sets data object class on the form and/or inquirable. 050 */ 051 @Override 052 public void postBind(HttpServletRequest request) { 053 super.postBind(request); 054 055 if (StringUtils.isBlank(getDataObjectClassName())) { 056 setDataObjectClassName(((InquiryView) getView()).getDataObjectClassName().getName()); 057 } 058 059 Inquirable inquirable = getInquirable(); 060 061 //KULRICE-12985 always update the data object class for inquirable, not just the first time. 062 if (inquirable != null) { 063 Class<?> dataObjectClass; 064 try { 065 dataObjectClass = Class.forName(getDataObjectClassName()); 066 } catch (ClassNotFoundException e) { 067 throw new RuntimeException("Object class " + getDataObjectClassName() + " not found", e); 068 } 069 070 inquirable.setDataObjectClass(dataObjectClass); 071 } 072 } 073 074 /** 075 * Returns an {@link org.kuali.rice.krad.inquiry.Inquirable} instance associated with the inquiry view. 076 * 077 * @return Inquirable instance or null if one does not exist 078 */ 079 public Inquirable getInquirable() { 080 if (getViewHelperService() != null) { 081 return (Inquirable) getViewHelperService(); 082 } 083 084 return null; 085 } 086 087 /** 088 * Class name of the data object the inquiry will display 089 * 090 * <p> 091 * Used to set the data object class for the <code>Inquirable</code> which 092 * is then used to perform the inquiry query 093 * </p> 094 * 095 * @return String class name 096 */ 097 public String getDataObjectClassName() { 098 return this.dataObjectClassName; 099 } 100 101 /** 102 * Setter for the inquiry data object class name 103 * 104 * @param dataObjectClassName 105 */ 106 public void setDataObjectClassName(String dataObjectClassName) { 107 this.dataObjectClassName = dataObjectClassName; 108 } 109 110 /** 111 * Result data object for inquiry that will be display with the view 112 * 113 * @return Object object instance containing the inquiry data 114 */ 115 public Object getDataObject() { 116 return this.dataObject; 117 } 118 119 /** 120 * Setter for the inquiry data object 121 * 122 * @param dataObject 123 */ 124 public void setDataObject(Object dataObject) { 125 this.dataObject = dataObject; 126 } 127 128 /** 129 * Indicates whether the requested was redirected from the inquiry framework due to an external object 130 * request. This prevents the framework from performing another redirect check 131 * 132 * @return boolean true if request was a redirect, false if not 133 */ 134 public boolean isRedirectedInquiry() { 135 return redirectedInquiry; 136 } 137 138 /** 139 * Setter for the redirected request indicator 140 * 141 * @param redirectedInquiry 142 */ 143 public void setRedirectedInquiry(boolean redirectedInquiry) { 144 this.redirectedInquiry = redirectedInquiry; 145 } 146 147}