开发者

JSF2 Converting List of String to String[]

having a bit of a spanner moment. I need to convert a List to String Array:

List<String> selectedIndicie to String[] targetIndices;

The selectedIndicie list is pulled from a backing bean and I attempt to convert it to a String array like so:

setTargetIndices(initial开发者_StackOverflowiseBean.getSelectedIndicie().toArray(getTargetIndices())); 

But Java has a right old moan saying:

An error occurred performing resource injection on managed bean searchBean

As I said I am having a spanner moment on how else to convert the List of Strings to an array of String so any suggests would be lovely.

Cheers


List.toArray returns an array of Objects, which is likely to result in an exception when you execute setTargetIndices for this method would be accepting an array of String objects. The answer is to not convert the setter to accept an array of Object (for the JSF runtime might simply fail to recognize the setter as belonging to the targetIndices property), rather it is to invoke the setter with an array of Strings.


As I said I am having a spanner moment on how else to convert the List of Strings to an array of String so any suggests would be lovely.

Use the toArray method.


try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜