001    /*
002     * Copyright 2011 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     */
016    package org.kuali.kfs.sys.document.web.util;
017    
018    import javax.servlet.jsp.PageContext;
019    
020    import org.kuali.rice.kns.util.GlobalVariables;
021    import org.kuali.rice.kns.util.WebUtils;
022    import org.kuali.rice.kns.web.struts.pojo.PojoFormBase;
023    
024    /**
025     * This class contains utility methods to help render accounting line elements
026     */
027    public class RendererUtil {
028        /**
029         * Registers a property name as on a form/JSP page as editable so that when the next request is submitted,
030         * the property will be properly populated on the form
031         * 
032         * @param pageContext
033         * @param editablePropertyName
034         */
035        public static void registerEditableProperty(PageContext pageContext, String editablePropertyName) {
036            PojoFormBase form = null;
037            if (pageContext.getRequest().getAttribute(WebUtils.KEY_KUALI_FORM_IN_SESSION) != null) {
038                form = (PojoFormBase) pageContext.getRequest().getAttribute(WebUtils.KEY_KUALI_FORM_IN_SESSION);
039            }
040            else if (pageContext.getSession().getAttribute(WebUtils.KEY_KUALI_FORM_IN_SESSION) != null) {
041                form = (PojoFormBase) pageContext.getSession().getAttribute(WebUtils.KEY_KUALI_FORM_IN_SESSION);
042            }
043            else {
044                form = (PojoFormBase) GlobalVariables.getKualiForm();
045            }
046            
047            if (form != null) {
048                form.registerEditableProperty(editablePropertyName);
049            }
050        }
051    }