首页>代码>JSF框架开发的入门级java web实例demo>/jsftest/src/convertertest/UserConverter.java
package convertertest;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class UserConverter implements Converter{

	/**
	 * 从前端传过来,转换成后台对象
	 * 		fc:
	 * 		arg1:
	 * 		str:前台传过来字符串
	 */
	public Object getAsObject(FacesContext fc, UIComponent arg1, String str) {
		String[] strs = str.split(",");
		User user = new User();
		try {
			user.setName(strs[0]);
			user.setAddress(strs[1]);
			}
		catch(Exception e) {
			// 转换错误,简单的丢出例外
			throw new ConverterException();
		}
		return user;
	}

	/**
	 * 从后台传出,转换成string
	 */
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		User mu=(User)arg2;
		return (mu.getName()+","+mu.getAddress());
	}
}
最近下载更多
通灵猫神  LV3 2022年4月20日
15947813008  LV5 2020年11月30日
wwwzzzjjj  LV15 2020年4月26日
1yyy23456789  LV6 2019年12月29日
hongxiaobing  LV2 2019年10月25日
张庭玉  LV8 2019年10月14日
mrhe118  LV3 2019年5月2日
itliuxue  LV1 2018年11月17日
htkycat  LV2 2018年6月15日
xixueguibu  LV1 2018年4月20日
最近浏览更多
fangeling 2023年2月14日
暂无贡献等级
通灵猫神  LV3 2022年4月20日
c123456x  LV2 2021年12月2日
niechristal  LV2 2021年11月23日
愿若流水  LV1 2020年12月12日
15947813008  LV5 2020年11月30日
Shuxian Dong  LV8 2020年8月23日
919032628 2020年8月21日
暂无贡献等级
614627929  LV10 2020年5月30日
wwwzzzjjj  LV15 2020年4月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友