no.abmu.abmstatistikk.annualstatistic.webflow.AnnualStatisticFormAction.java Source code

Java tutorial

Introduction

Here is the source code for no.abmu.abmstatistikk.annualstatistic.webflow.AnnualStatisticFormAction.java

Source

/*$Id: AnnualStatisticFormAction.java 7855 2008-01-30 13:00:53Z jens $*/
/*
 ****************************************************************************
 *                                                                          *
 *                   (c) Copyright 2008 ABM-utvikling                       *
 *                                                                          *
 * This program is free software; you can redistribute it and/or modify it  *
 * under the terms of the GNU General Public License as published by the    *
 * Free Software Foundation; either version 2 of the License, or (at your   *
 * option) any later version.                                               *
 *                                                                          *
 * This program is distributed in the hope that it will be useful, but      *
 * WITHOUT ANY WARRANTY; without even the implied warranty of               *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
 * Public License for more details. http://www.gnu.org/licenses/gpl.html    *
 *                                                                          *
 ****************************************************************************
 */
package no.abmu.abmstatistikk.annualstatistic.webflow;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.util.StopWatch;

import org.springframework.webflow.action.FormAction;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;

/**
 * <code>AnnualStatisticFormAction</code> takes care of all webflow 
 * form handling on AnnualStatistic schemas. 
 * 
 * @author Jens Vindvad, Jens.Vindvad@abm-utvikling.no
 * @author $Author: jens $
 * @version $Rev: 7855 $
 * @date $Date: 2008-01-30 14:00:53 +0100 (Wed, 30 Jan 2008) $
 * @since 2008-01-25
 * copyright ABM-Utvikling
 */
public class AnnualStatisticFormAction extends FormAction {

    private static final Log logger = (Log) LogFactory.getLog(AnnualStatisticFormAction.class);

    private WebFlowService webFlowService;

    public WebFlowService getWebFlowService() {
        return webFlowService;
    }

    public void setWebFlowService(WebFlowService webFlowService) {
        this.webFlowService = webFlowService;
    }

    protected Object createFormObject(RequestContext context) {
        if (logger.isDebugEnabled()) {
            logger.debug("Executing createFormObject");
        }
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("createFormObject");

        WebSchemaDefinition webSchema = webFlowService.createWebSchema(context);

        String submitEvent = context.getRequestParameters().get("_eventId_submit.y");
        if (submitEvent == null) {
            // Getting values from database into webSchema 
            // and show these values to user
            // e.g. webSchema --> formObject to user
            if (logger.isDebugEnabled()) {
                logger.debug("[createFormObject] submitEvent == null (webSchema --> formObject to user) ");
            }
        } else {
            // Getting values from user and sending user input 
            // to binding and eventually validation.
            // e.g. webSchema --> formObject from user
            if (logger.isDebugEnabled()) {
                logger.debug("[createFormObject] submitEvent != null (webSchema --> formObject from user)");
            }
        }
        webFlowService.databaseValuesToWebSchema(webSchema);

        stopWatch.stop();
        logger.info("[createFormObject] tok [" + stopWatch.getTotalTimeMillis() + "] ms");

        return webSchema;
    }

    public Event schemaProcessForSchoolLibrary(RequestContext context) throws Exception {
        if (logger.isDebugEnabled()) {
            logger.debug("Executing schemaProcessForSchoolLibrary");
        }

        String field405 = context.getRequestParameters().get("field405");
        String field226 = context.getRequestParameters().get("field226");

        if (field405 == null || field226 == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("field405==null or field226==null, user has to fill out full schema.");
            }
            return new Event(this, "fullSchema");
        }

        if (field405.equals("false") && field226.equals("false")) {
            if (logger.isDebugEnabled()) {
                logger.debug("field405 and field226 are both false, user has to fill out short schema.");
            }
            return new Event(this, "shortSchema");
        }
        return new Event(this, "fullSchema");
    }
}