3
回答
求助:Struts2 配置TypeConverter,转换后Action里对象为NULL
注册华为云得mate10,2.9折抢先购!>>>   

src下:xwork-conversion.properties 内容:
net.ynyee.jzone.pojo.ArticleClass=net.ynyee.jzone.typeconverter.ArticleClassTypeConverter 

 

public class ArticleClassTypeConverter extends StrutsTypeConverter {
	@Override
	public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
		int classId = Integer.valueOf(arg1[0]);
		ArticleClass articleClass = new ArticleClass();
		articleClass.setId(classId);
		return articleClass;
	}
	@Override
	public String convertToString(Map arg0, Object arg1) {
		return String.valueOf(((ArticleClass) arg1).getId());
	}
}

 

 可以执行到articleClass.setId(classId);后

Action里面有Article对象,Article里有个ArticleClass对象。页面上代码是:

 

<select name="article.articleClass">
			<!--  <#list application.articleClassesList as class> -->
				<option value="${class.id}" title="${class.description}">${class.name}</option>
			<!-- </#list> -->
</select>

 

 

Action中输出article.getArticleClass()是NULL

举报
顶部