JSF2将字符串列表转换为String []

时间:2011-08-04 17:25:44

标签: java jsf-2

有一点扳手的时刻。我需要将List转换为String Array:

List<String> selectedIndicieString[] targetIndices;

selectedIndicie列表是从支持bean中提取的,我尝试将其转换为String数组,如下所示:

setTargetIndices(initialiseBean.getSelectedIndicie().toArray(getTargetIndices())); 

但是Java有一个正确的老呻吟说:

  

在托管bean searchBean上执行资源注入时发生错误

正如我所说,我正在研究如何将字符串列表转换为字符串数组,以便任何建议都是可爱的。

干杯

3 个答案:

答案 0 :(得分:1)

List.toArray返回一个Object数组,当你执行setTargetIndices时,这可能会导致异常,因为这个方法会接受String个对象的数组。答案是不将setter转换为接受Object数组(对于JSF运行时可能只是无法将setter识别为属于targetIndices属性),而是调用setter一系列字符串。

答案 1 :(得分:0)

  

正如我所说,我正在寻找一个关于如何转换List的扳手   字符串数组的字符串,所以任何建议都很可爱。

使用toArray方法。

答案 2 :(得分:0)

试试这个:

String[] targetIndices = selectedIndicie.toArray(new String[selectedIndicie.size()]);