www.pudn.com > struts2.rar > PointConverter2.java, change:2009-08-18,size:1053b


package com.test.converter; 
 
import java.util.Map; 
 
import org.apache.struts2.util.StrutsTypeConverter; 
 
import com.test.bean.Point; 
 
public class PointConverter2 extends StrutsTypeConverter { 
	 
	/* 
	 * (non-Javadoc) 
	 * @see org.apache.struts2.util.StrutsTypeConverter#convertFromString(java.util.Map, java.lang.String[], java.lang.Class) 
	 * 从字符串转换成对象 
	 */ 
	public Object convertFromString(Map arg0, String[] arg1, Class arg2) { 
		Point point = new Point(); 
		String[] paramValues = arg1[0].split(","); 
		int x = Integer.parseInt(paramValues[0]); 
		int y = Integer.parseInt(paramValues[1]); 
		 
		point.setX(x); 
		point.setY(y); 
		 
		return point; 
	} 
	 
	/* 
	 * (non-Javadoc) 
	 * @see org.apache.struts2.util.StrutsTypeConverter#convertToString(java.util.Map, java.lang.Object) 
	 * 从对象转换成字符串 
	 */ 
	public String convertToString(Map arg0, Object arg1) { 
		Point point = new Point(); 
		point = (Point)arg1; 
		String result = "[x=" + point.getX() + ",y=" + point.getY() + "]"; 
		return result; 
	} 
}