如何通过自定义 Struts 类型转换器转换列表项的字段? [英] How to convert field of the list item via custom Struts type converter?

查看:40
本文介绍了如何通过自定义 Struts 类型转换器转换列表项的字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为CompanyEmployee 类中的ID 字段实现自定义转换.我已经实现了从 StrutsTypeConverter 扩展的自定义转换器,它成功地用于转换 Company.ID 字段,但它不适用于 Employee.ID>.

I need to implement custom conversion for ID field in Company and Employee classes. I have already implemented custom converter extended from StrutsTypeConverter and it is successfully used to convert Company.ID field, but it does not work for Employee.ID.

似乎主要问题出在转换属性文件中.我应该如何在转换属性文件中为员工 ID 字段指定转换器类?

Seems like the main problem is in conversion properties file. How should I specify converter class for employee ID field in conversion properties file?

MyAction-conversion.properties:

company.id = com.struts2.convertors.MyCustomConverter
company.??????.id = com.struts2.convertors.MyCustomConverter

MyAction:

public class MyAction extends ActionSupport {

    private Company company;

    public Company getCompany () {
        return company;
    }
    public void setCompany (Company company) {
        this.company= company;
    }
    @Override
    public String execute() {
        return SUCCESS;
    }
}

公司:

public class Company {

    private ID id;

    private List<Employee> employees;

    // getters and setters
}

员工

public class Employee{

    private ID id;

    private String name;

    // getters and setters
}

推荐答案

尝试以下操作,将 ID 类型的转换器添加到 xwork-conversion.properties 文件

Try the following by adding a converter for the ID type to the xwork-conversion.properties file

com.struts2.ID = com.struts2.convertors.MyCustomConverter

这篇关于如何通过自定义 Struts 类型转换器转换列表项的字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆