?? mapform.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 + -