Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

newbie: "Cannot coerce type java.lang.String[] to java.lang.String..."

843844Jun 4 2009 — edited Jun 4 2009
Hi, i'm new to jsf (and jsp). This is my first app using eclipse 3.4, tomcat6, and jsf1.2.12. Although there has been a learning curve, but I've been picking up new knowledge everyday.

I was trying to create a check box list binding to an array of strings as data source in a jsf page, this code seems to work, but eclipse kept complain about:

"Cannot coerce type java.lang.String[] to java.lang.String, java.lang.Short,
java.lang.Character, java.lang.Boolean, java.lang.Double, java.lang.Byte, java.lang.Long,
java.lang.Float, java.lang.Integer"

the following are my codes:

test.jsf
<h:selectManyCheckbox id="chboxlist" value="#{myBean.selectedItems}">
       	<f:selectItems value="#{myBean.myList}"/>
</h:selectManyCheckbox>
<h:commandButton value="submit" action="#{myBean.action}" />
myBean.java
private List<SelectItem> myList;  //with getter/setter
private String[] selectedItems;  //with getter/setter

public MyBean(){
		//pre-populate checkbox/radio/menu list
		myList = new ArrayList<SelectItem>();
		myList.add(new SelectItem("one", "one"));
		myList.add(new SelectItem("two", "two"));
		myList.add(new SelectItem("three", "three"));
	}//constructor

public void action(){
		for(String value : selectedItems){
			System.out.println(" I picked: " + value;)
		}
	}//action
since eclipse complained, I must did something wrong, even hough the code above works. What else am I missing?
Thank you.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 2 2009
Added on Jun 4 2009
1 comment
1,033 views