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

📄 mapform.java

📁 struts + spring + hibernate的例子,用IntelliJ IDEA制作
💻 JAVA
字号:
/*
 * Copyright (c) 2004 Your Corporation. All Rights Reserved.
 */
package net.jetmaven.form;

import org.apache.struts.action.*;
import org.apache.struts.validator.ValidatorForm;

import javax.servlet.http.*;
import javax.servlet.ServletRequest;
import java.util.*;

import net.jetmaven.util.RowIdComparator;

/**
 * Map方式的ActionForm
 * User: <a href="mailto:linux_china@hotmail.com">chenlibing</a>
 * Date: 2004-2-1
 *
 * @struts.form name="MapForm"
 */
public class MapForm extends ActionForm
{
    private Map attributeMap = new HashMap();

    public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest)
    {
        this.attributeMap.clear();
    }

    /**
     * Wrapper around the hash map. I can change the underlying Map object without
     * breaking the rest of the code.
     *
     * @returns The map containg the attributes.
     */
    public Map getMap()
    {
        return attributeMap;
    }

    public void setMap(Map attributeMap)
    {
        this.attributeMap = attributeMap;
    }

    /**
     * Sets a form bean attribute in the form's internal Map.
     *
     * @param attributeKey   Name of the attribute.
     * @param attributeValue Attribute value to be stored. This must be a Java object and not a primitive.
     */
    public void setAttribute(String attributeKey, Object attributeValue)
    {
        getMap().put(attributeKey, attributeValue);
    }

    /**
     * Returns the individual attribute.
     *
     * @param attributeKey Name of the attribute being looked up
     * @return An the object. If the object is null it returns an empty "".
     */
    public Object getAttribute(String attributeKey)
    {
        Object holder = getMap().get(attributeKey);
        if (holder == null) return "";
        return holder;
    }

    public void reset(ActionMapping actionMapping, ServletRequest servletRequest)
    {
        attributeMap.clear();
    }

    /**
     * 获取行数据的行标识,如表格方式的数据,同一行数据采用相同的前缀,如row8899_name
     *
     * @return 行标识列表
     */
    public Collection getRowIdList(String rowPrefix)
    {
        if (attributeMap.isEmpty()) return new ArrayList();
        Collection allRowId = new TreeSet(new RowIdComparator("row"));
        Iterator allKey = attributeMap.keySet().iterator();
        while (allKey.hasNext())
        {
            String key = (String) allKey.next();
            if (key.indexOf(rowPrefix) != -1)
            {
                key = key.substring(0, key.indexOf('_'));
                allRowId.add(key);
            }
        }
        return allRowId;
    }

}

⌨️ 快捷键说明

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