0

Is it possible to write converter which can convert String[] to String?

<p:selectManyCheckbox value="#{bean.numbers}" > 
  <f:selectItem itemValue="Number10" itemLabel="Number 10" />
  <f:selectItem itemValue="Number20" itemLabel="Number 20" />
  <f:selectItem itemValue="Number30" itemLabel="Number 30" />
  <f:converter converterId="arrayStringConverter"/>
</p:selectManyCheckbox>

I need to declare #{bean.numbers} as String. I know that selectManyCheckbox requires Array or Collection.

How can I write converter that can convert array to separated string? I've tried using f:converter but it's called for every f:selectItem, but not for the whole component value.

4

1 回答 1

1

JSF 转换器重复应用于每个单独的项目,而不是您似乎期望的整个集合/数组一次。所以,不,这是不可能的。如果您绝对需要像这样畸形模型,只需在业务层执行转换工作。

(如果我猜对了您实际尝试做的事情,将多个值存储在单个数据库列中;开始阅读有关数据库规范化、外键关系和 JOIN 的信息)

于 2013-07-11T16:25:01.167 回答