JSF和表达式语言:仅在存在属性时绑定属性 [英] JSF and expression language: Bind property only when it exists

查看:77
本文介绍了JSF和表达式语言:仅在存在属性时绑定属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将数据列绑定到数据源中可能存在或可能不存在的属性的最佳方法是什么?

what is the best way to bind a datacolumn to a property that might or might not exist in the datasource?

例如,当您具有一个类层次结构时,其中某些子类可能是具有该属性的子类型,就会发生这种情况.数据源包含各种子类类型.

This happens for example when you have a class hierarchy where some children might be of a subtype which has the property. The datasource contains various subclass types.

<DataColumn outputText="#{item.property}" />

当子类之一中不存在该属性时,

始终会产生PropertyNotFoundException.我不想在基类中包含该属性,因为根据业务规则,该属性不应存在.

always yields a PropertyNotFoundException when the property isn't present in one of the subclasses. I don't want to include the property in the base class because it shouldn't be there according to the business rules.

您将如何解决此问题?

推荐答案

在这种情况下,我认为最好的方法是为具有所有必要字段的视图层创建自定义实体,并将要显示的项目转换为它.

I think the best way in such a case is to create a custom entity for the view tier with all the necessary fields and convert the items you want to display to it.

这篇关于JSF和表达式语言:仅在存在属性时绑定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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