⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hasgeneratedidformbean.java

📁 A Java web application, based on Struts and Hibernate, that serves as an online running log. Users m
💻 JAVA
字号:
/* @LICENSE_COPYRIGHT@ */
package net.sf.irunninglog.servlet.formbean;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionMapping;

import net.sf.irunninglog.canonical.HasGeneratedId;
import net.sf.irunninglog.servlet.UserContainer;
import net.sf.irunninglog.util.ConstantValues;
import net.sf.irunninglog.util.DTO;
import net.sf.irunninglog.util.Utilities;

/**
 * Value bean representation of any object with a generated <em>id</em> field.
 * Contains any logic needed to access, udpate, or reset the field's value.
 *
 * @author <a href="mailto:allan_e_lewis@yahoo.com">Allan Lewis</a>
 * @version $Revision: 1.1.1.1 $ $Date: 2005/06/23 01:49:01 $
 * @since iRunningLog 1.0
 */
public abstract class HasGeneratedIdFormBean extends HasRunnerIdFormBean {

    /** <code>Log</code> instance for this class. */
    private static final Log LOG =
                                LogFactory.getLog(HasGeneratedIdFormBean.class);

    /** The bean's <em>id</em> field. */
    private String mId;

    /**
     * Get the value of the bean's <em>id</em> field.
     *
     * @return The current value of the <em>id</em> field
     */
    public String getId() {
        return mId;
    }

    /**
     * Set the value of the bean's <em>id</em> field.
     *
     * @param value The value to be set onto the <em>id</em> field
     */
    public void setId(String value) {
        mId = value;
    }

    /**
     * Retrieve the form bean's values.
     *
     * @return A transfer object representing the for bean's state
     */
    public DTO getValues() {
        DTO valueObject = super.getValues();

        if (LOG.isDebugEnabled()) {
            LOG.debug("getValues: Contents of the value object "
                      + " (before) " + valueObject);
        }

        valueObject.setValue(HasGeneratedId.FIELD_ID, getId());

        if (LOG.isDebugEnabled()) {
            LOG.debug("getValues: Contents of the value object "
                      + " (after) " + valueObject);
        }

        return valueObject;
    }

    /**
     * Update the form bean's values.
     *
     * @param valueObject Value object containing the new values
     *                    to be applied to the form bean
     */
    public void setValues(DTO valueObject) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("setValues: Contents of the value object "
                      + valueObject);
        }

        super.setValues(valueObject);

        setId(valueObject.getValue(HasGeneratedId.FIELD_ID));
    }

    /**
     * Reset the state of the form bean.  This will reset the value of the
     * <em>id</em> field if it is null (using the value from
     * <code>UserContainer.getUserName()</code>).
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     * @param container The current user's container object
     * @see UserContainer#getUserName()
     */
    protected void reset(ActionMapping mapping, HttpServletRequest request,
                                               UserContainer container) {

        super.reset(mapping, request, container);
        String value = null;

        if (Utilities.isBlank(getId())) {
            value = ConstantValues.STRING_UNSAVED_VALUE;

            if (LOG.isDebugEnabled()) {
                LOG.debug("reset: Resetting the id to '" + value + "'");
            }

            setId(value);
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -