/*
 * ICESOFT COMMERCIAL SOURCE CODE LICENSE V 1.1
 *
 * The contents of this file are subject to the ICEsoft Commercial Source
 * Code License Agreement V1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of the
 * License at
 * http://www.icesoft.com/license/commercial-source-v1.1.html
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * Copyright 2009-2015 ICEsoft Technologies Canada, Corp. All Rights Reserved.
 */

package com.icesoft.faces.application.showcase.util;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

/**
 * The submit mode allows the showcase to switch from either a partialSubmit
 * ICEfaces 1.8.2 compat mode to ICEfaces 2.0 single submit mode.  The two mode
 * can't live in the same form.
 * <p/>
 * This bean is configurable via the context param
 * com.icesoft.faces.application.showcase.submitMode.singleSubmit in the web.xml
 */
@ApplicationScoped
@ManagedBean
public class SubmitMode {

    private boolean isSingleSubmit;

    public SubmitMode() {
        // grab the submit mode from the web.xml context parameter.
        isSingleSubmit = Boolean.parseBoolean(FacesUtils.getFacesParameter(
                "com.icesoft.faces.application.showcase.submitMode.singleSubmit"));
    }

    /**
     * Indicates which submit mode is enabled for the application
     *
     * @return true if single submit is enabled and false if partial submit
     *         is enabled.
     */
    public boolean isSingleSubmit() {
        return isSingleSubmit;
    }

    /**
     * Indicates which submit mode is enabled for the application
     *
     * @return true if single submit is enabled and false if partial submit
     *         is enabled.
     */
    public boolean isPartialSubmit() {
        return !isSingleSubmit;
    }
}
