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.mock;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.krad.uif.util.SessionTransient;
020import org.kuali.rice.krad.web.form.UifFormBase;
021import org.springframework.web.bind.annotation.RequestMethod;
022
023import javax.servlet.http.HttpServletRequest;
024import java.util.Map;
025
026/**
027 * Form class for {@link org.kuali.rice.krad.uif.mock.MockView} instances that holds data in generic maps.
028 *
029 * @author Kuali Rice Team (rice.collab@kuali.org)
030 */
031public class DynaForm extends UifFormBase {
032    private static final long serialVersionUID = -2112462466031059707L;
033
034    private Map<String, Object> data;
035    private Map<String, Boolean> booleanData;
036
037    @SessionTransient
038    private boolean initialGetRequest;
039
040    /**
041     * Default constructor.
042     */
043    public DynaForm() {
044        super();
045    }
046
047    /**
048     * {@inheritDoc}
049     */
050    @Override
051    public void postBind(HttpServletRequest request) {
052        // form key is assigned in super so need to do this check before it executes
053        if (StringUtils.isBlank(getFormKey()) && request.getMethod().equals(RequestMethod.GET.name())) {
054            initialGetRequest = true;
055        }
056
057        super.postBind(request);
058    }
059
060    /**
061     * Map containing non-boolean data for the view.
062     *
063     * @return map where key is property name and value is the property value
064     */
065    public Map<String, Object> getData() {
066        return data;
067    }
068
069    /**
070     * @see DynaForm#getData()
071     */
072    public void setData(Map<String, Object> data) {
073        this.data = data;
074    }
075
076    /**
077     * Map containing boolean data for the view.
078     *
079     * @return map where key is property name and value is the property value
080     */
081    public Map<String, Boolean> getBooleanData() {
082        return booleanData;
083    }
084
085    /**
086     * @see DynaForm#getBooleanData()
087     */
088    public void setBooleanData(Map<String, Boolean> booleanData) {
089        this.booleanData = booleanData;
090    }
091
092    /**
093     * Indicates whether the request is the initial get request for the view.
094     *
095     * @return boolean true if this is the initial request, false if not
096     */
097    public boolean isInitialGetRequest() {
098        return initialGetRequest;
099    }
100}