繁体   English   中英

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

[英]JSF2 Converting List of String to String[]

有点扳手的时刻。 我需要将列表转换为字符串数组:

List<String> selectedIndicieString[] targetIndices;

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

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

但是Java有一个正确的古老mo吟:

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

就像我说的那样,我正在探讨如何将字符串列表转换为字符串数组,以便任何建议都可以。

干杯

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

就像我说的那样,我正在探讨如何将字符串列表转换为字符串数组,以便任何建议都可以。

使用toArray方法。

尝试这个:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM