Spring mvc liferay spring mvc注释格式化程序工厂

Spring mvc liferay spring mvc注释格式化程序工厂,spring-mvc,liferay,Spring Mvc,Liferay,使用liferay 6.0.x,我试图将一个自定义AnnotationFormatterFactory注册到我的SpringMVCPortlet,但它不使用它来转换我的pojo属性。 这是我的代码: 我的注解: @Target(value = ElementType.FIELD) @Retention(value = RetentionPolicy.RUNTIME) public @interface ListSelector { public enum ListSelectorTyp

使用liferay 6.0.x,我试图将一个自定义AnnotationFormatterFactory注册到我的SpringMVCPortlet,但它不使用它来转换我的pojo属性。 这是我的代码:

我的注解:

@Target(value = ElementType.FIELD)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface ListSelector {

    public enum ListSelectorType {
        UTILISATEURS
    }

    ListSelectorType type();
    boolean useReferentiel() default true;

}
我的格式化程序:

public class ListSelectorUtilisateurFormater implements Formatter<List> {

    private static final Log LOG = LogFactory.getLog(ListSelectorUtilisateurFormater.class);

    public ListSelectorUtilisateurFormater() {
    }

    @Override
    public String print(final List listeUtilisateurs, final Locale locale) {
        try {
            return ConvertJSONUtilForListSelector.convertUserToJSON(listeUtilisateurs).toString();
        } catch (JSONException e) {
            ListSelectorUtilisateurFormater.LOG.error("error formatting user list to JSON", e);
            return null;
        }
    }

    @Override
    public List parse(final String formatted, final Locale locale) throws ParseException {
        List<String> extractedIds;
        List<Utilisateur> users = new ArrayList<Utilisateur>();
        if (StringUtils.isNotBlank(formatted)) {
            extractedIds = Arrays.asList(formatted.split(","));
                // génére une liste d'utilisateurs n'ayant que des ids
                for (final String id : extractedIds) {
                    final Utilisateur user = new Utilisateur();
                    user.setId(id);
                    users.add(user);
                }
        }
        return users;
    }

}
公共类ListSelector利用器Formatter实现格式化程序{
私有静态最终日志日志=LogFactory.getLog(ListSelector或UsalisateUrFormatter.class);
公共列表选择器或利用表格式器(){
}
@凌驾
公共字符串打印(最终列表ListUsiateurs、最终区域设置){
试一试{
返回ConvertJSONUtilForListSelector.convertUserToJSON(ListUsiateurs.toString();
}捕获(JSONException e){
ListSelectorUsiateUrFormatter.LOG.error(“将用户列表格式化为JSON时出错”,e);
返回null;
}
}
@凌驾
公共列表解析(最终字符串格式,最终语言环境)引发ParseException{
列出提取的EDID;
列表用户=新建ArrayList();
if(StringUtils.isNotBlank(格式化)){
extractedIds=Arrays.asList(格式化为.split(“,”);
//génére是一个用人单位
for(最终字符串id:extractedIds){
最终用户=新用户();
user.setId(id);
用户。添加(用户);
}
}
返回用户;
}
}
My AnnotationFormatterFactory:

public class ListSelectorFormatterFactory implements AnnotationFormatterFactory<ListSelector> {

    private final Set<Class<?>> fieldTypes;

    public ListSelectorFormatterFactory(
                UtilisateurService utilisateurService) {

        Set<Class<?>> rawFieldTypes = new HashSet<Class<?>>(1);
        rawFieldTypes.add(List.class);
        this.fieldTypes = Collections.unmodifiableSet(rawFieldTypes);
    }

    @Override
    public Set<Class<?>> getFieldTypes() {

        return this.fieldTypes;
    }

    @Override
    public Printer<?> getPrinter(ListSelector annotation, Class<?> fieldType) {

        return configureFormatterFrom(annotation, fieldType);
    }

    @Override
    public Parser<?> getParser(ListSelector annotation, Class<?> fieldType) {

        return configureFormatterFrom(annotation, fieldType);
    }

    private Formatter<?> configureFormatterFrom(ListSelector annotation, Class<?> fieldType) {

        switch (annotation.type()) {
            case UTILISATEURS:
                        return new ListSelectorUtilisateurFormater();
            default:
                return null;
        }

    }

}
公共类ListSelectorFormatterFactory实现注释FormatterFactory{
private final Set>rawFieldTypes=new HashSet>getFieldTypes(){
返回此字段。字段类型;
}
@凌驾
公共打印机getPrinter(ListSelector注释,类字段类型){
返回configureFormatterFrom(注释,字段类型);
}
@凌驾
公共解析器getParser(ListSelector注释,类fieldType){
返回configureFormatterFrom(注释,字段类型);
}
专用格式化程序configureFormatterFrom(ListSelector注释,类fieldType){
开关(annotation.type()){
个案使用人:
返回新的ListSelector使用Urformator();
违约:
返回null;
}
}
}
我的pojo(我尝试了原生spring注释,但它们也不起作用):

公共类Pojo{
@ListSelector(类型=ListSelector.ListSelectorType.UtiliteAturs)
私有列表测试=新建ArrayList();
@ListSelector(类型=ListSelector.ListSelectorType.UtiliteAturs)
私人提款人[]测试2;
@DateTimeFormat(iso=DateTimeFormat.iso.TIME)
私人日期;
公共列表getTest(){
回归试验;
}
公共无效设置测试(列表测试){
这个。测试=测试;
}
公共日期getDate(){
返回日期;
}
公共作废设置日期(日期){
this.date=日期;
}
}
最后是我的applicationContext.xml(我尝试了mcv:annotation-driven和AnnotationMethodHandlerAdapter方法):

pjo注释在我的jsp中都不起作用:

[${testPojo.date}][<spring:eval expression="testPojo.date" />][<spring:bind path="testPojo.date">${status.value}</spring:bind>]<br/>
            [${testPojo.test}][<spring:eval expression="testPojo.test" />][<spring:bind path="testPojo.test">${status.value}</spring:bind>]<br/>
[${testPojo.date}][${status.value}]
[${testPojo.test}][${status.value}]
第一个[]给我列表引用或未格式化的日期,第二个和第三个[]什么也不给我


有人知道如何在liferay中使用AnnotationFormatterFactory或standart spring格式化程序吗?

找到解决方案了吗?
[${testPojo.date}][<spring:eval expression="testPojo.date" />][<spring:bind path="testPojo.date">${status.value}</spring:bind>]<br/>
            [${testPojo.test}][<spring:eval expression="testPojo.test" />][<spring:bind path="testPojo.test">${status.value}</spring:bind>]<br/>