java.lang.IllegalArgumentException.Why?

Hi guys....

i'm a doubt and a problems but i'm not able to solve it!

Please help me...

I have a form in a jsp page of my jsf application in which i have to insert a login, a password and a team and there is a button that ,once clicked,performs authentication.I've developed a wrapper class with the 3forms as private variables and strings and everythings go well.

Now i want to change team input,giving the user the possibility to choice a value from a list based on a db query.

I've this error when i run the application

java.lang.IllegalArgumentException: Value binding'#{user.teams}'of UISelectItems with component-path{Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /Login.jsp][Class: javax.faces.component.html.HtmlForm,Id: _id1][Class: javax.faces.component.html.HtmlPanelGrid,Id: _id2][Class: javax.faces.component.html.HtmlPanelGrid,Id: _id4][Class: javax.faces.component.html.HtmlSelectOneListbox,Id: _id17][Class: javax.faces.component.UISelectItems,Id: _id18]} does not reference an Object of type SelectItem, SelectItem[], Collection or Map but of type :null

org.apache.myfaces.shared_impl.util.SelectItemsIterator.hasNext(SelectItemsIterator.java:141)

org.apache.myfaces.shared_impl.renderkit.RendererUtils.internalGetSelectItemList(RendererUtils.java:477)

org.apache.myfaces.shared_impl.renderkit.RendererUtils.getSelectItemList(RendererUtils.java:453)

org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.internalRenderSelect(HtmlRendererUtils.java:277)

org.apache.myfaces.shared_impl.renderkit.html.HtmlRendererUtils.renderListbox(HtmlRendererUtils.java:240)

org.apache.myfaces.shared_impl.renderkit.html.HtmlListboxRendererBase.encodeEnd(HtmlListboxRendererBase.java:73)

javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:720)

org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:442)

org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.renderChildren(HtmlGridRendererBase.java:216)

org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.encodeEnd(HtmlGridRendererBase.java:98)

javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:720)

org.apache.myfaces.shared_impl.renderkit.RendererUtils.renderChild(RendererUtils.java:442)

org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.renderChildren(HtmlGridRendererBase.java:216)

org.apache.myfaces.shared_impl.renderkit.html.HtmlGridRendererBase.encodeEnd(HtmlGridRendererBase.java:98)

javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:720)

javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:623)

javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:546)

com.sun.faces.taglib.html_basic.PanelGridTag.doEndTag(PanelGridTag.java:460)

org.apache.jsp.Login_jsp._jspx_meth_h_panelGrid_0(Login_jsp.java:245)

org.apache.jsp.Login_jsp._jspx_meth_h_form_0(Login_jsp.java:207)

org.apache.jsp.Login_jsp._jspx_meth_f_view_0(Login_jsp.java:159)

org.apache.jsp.Login_jsp._jspService(Login_jsp.java:102)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)

com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)

com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)

com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)

com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)

javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)

org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:670)

org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:637)

org.apache.jsp.index_jsp._jspService(index_jsp.java:43)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)

javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

my jsp page is simple

<h:form>

<h:panelGrid columns="2" border="0" cellpadding="3" cellspacing="3">

<h:graphicImage url="/images/logo.gif" alt="Welcome to ProjectTrack"

title="Welcome MicroArray" width="149" height="160"/>

<h:panelGrid columns="3" border="0" cellpadding="5" cellspacing="3"

headerClass="login-heading">

<f:facet name="header">

<h:outputText value="Welcome to MicroArray Application" />

</f:facet>

<h:messages globalOnly="true"/>

<h:outputLabel for="userNameInput">

<h:outputText value="Enter your user name:"/>

</h:outputLabel>

<h:inputText value="#{authenticationBean.loginName}">

<f:validateLength minimum="5" maximum="30"/>

</h:inputText>

<h:message for="userNameInput" styleClass="errors"/>

<h:outputLabel for="passwordInput">

<h:outputText value="Password:"/>

</h:outputLabel>

<h:inputSecret value="#{authenticationBean.password}">

<f:validateLength minimum="5" maximum="30"/>

</h:inputSecret>

<h:message for="passwordInput" styleClass="errors"/>

<h:outputLabel for="teamInput">

<h:outputText value="Team:"/>

</h:outputLabel>

<h:selectOneListbox value="#{user.teamname}">

<f:selectItems value="#{user.teams}"/>

</h:selectOneListbox>

<h:commandButton action="#{authenticationBean.login}" value="Login"/>

</h:panelGrid>

</h:panelGrid>

</h:form>

and my list of values is generated by

public List<SelectItem> teamList()throws SQLException{

try{

DataSource dataSource=Singleton.getInstance().getDataSource();

Connection conn2=dataSource.getConnection();

Statement stmt = conn2.createStatement();

ResultSet rst = stmt

.executeQuery("select * from researchteam order by teamname");

List<SelectItem> teams =new ArrayList<SelectItem>();

while (rst.next())

teams.add(new SelectItem(rst.getString("teamname"),rst.getString("teamname")));

rst.close();

conn2.close();

}

catch(Exception e){};

return teams;

}

what have i do?

Can you say me what code have i to add to run the application?

Please help me,give me help or examples....thanks very much

[8863 byte] By [giubata] at [2007-10-3 1:30:27]
# 1
first check: ensure there are no null values coming back from the resultset - if there that may be the problem - it maybe the message is not as explicit as it could be
paroconsulta at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
How does getTeams() look like?
BalusCa at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

private List<SelectItem> teams;

public List<SelectItem> getTeams() {

return teams;

}

public void setTeams(List<SelectItem> teams) {

this.teams = teams;

}

what can i check?

Please help me simply,i'm a new user of jsf and java but i'm crazying for this problem..........it seems there is no solution...

please help me...

how can i check that my query results is not null?

Doing the same query on mysql give me the right results....

giubata at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

when talking about null columns - do the following:

String teamName = rst("teamName").toString();

if(teamName != null){

.... create the new list item;

}

OR

change the query so that the results do not return rows that have a null value for teamName; if when you run the query in MySQL there are no teamName columns with null i.e. they are empty values, then this is not the problem.

paroconsulta at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
sorry mistyped:String teamName = rst.getString("teamname");if(teamName != null)....
paroconsulta at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
thanks veru much for your availability...but what can i do?what i have to write in else?Have i debug the code?Can you help me,it's the first times i work with java,Jsf and Eclipse....please help me...
giubata at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
ok, when you run the query in mysql - do you get any columns where the teamname has nothing in it - meaning its empty?
paroconsulta at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

ok, so I went ahead and tried to break down your code - from what you posted it quickly became obvious - apologies for not spotting this - but the proof is always in the trying I guess - the problem is this - the function getTeams() return a null List object which has not been populated yet - although you have this function teamList() there is nowhere where this code gets executed to generate the list - this is what I have and ran succesfully - I took away the database side of things during my test but essentially the problem did not lie there:

public class Teams {

public Teams() {

}

public List<SelectItem> getTeams(){

return teamList();

}

public List<SelectItem> teamList() throws SQLException{

List<SelectItem> teams = null;

try {

teams = new ArrayList<SelectItem>();

// **** put in some code to get the connection and statement ****

teams = new ArrayList<SelectItem>();

Connection connection = null;

PreparedStatement ps = connection.prepareStatement("select * from researchteam order by teamname where teamname is not null");

ResultSet rst = ps.executeQuery();

while (rst.next()) {

String teamName = rst.getString("teamname");

teams.add(new SelectItem(teamName, teamName));

}

rst.close();

connection.close();

} catch(SQLException e_sql){

// log something

throw e_sql;

}

catch (Exception e)

{

// log something

}

return teams;

}

}

in your bean #{user.teams} - the beans getTeams function would get called which calls out to the teamList returning a list of SelectItems -

I downloaded the source for myfaces from http://people.apache.org/builds/myfaces/nightly/ and looked at where the problem resulted from - then looking at your code its quite clear you are a returning a null object from getTeams() - the setTeams function is not really required as it doesn't get called -

Have a look at the above and let me know if you have any more questions -

also I modified your query to return only rows where teamname has a value and I also used a preparedStatement instead so it gets precompiled and if you call the statement again it should be available in the cache

Lee

paroconsulta at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

thanks very much paroconsult....

you're a new user but my only hope...

i have not understood everythings due to my java and jsf inexperience and poor english.

I've a User bean so made

package giu;

import java.io.Serializable;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.ArrayList;

import java.util.List;

import javax.faces.model.SelectItem;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.sql.DataSource;

public class User implements Serializable {

private static final long serialVersionUID = 1;

private String firstName;

private String lastName;

private String date;

private String city;

private String address;

private String profession;

private String email;

private String login;

private String password;

private String teamname;

private String role;

private Connection conn;

private List<SelectItem> teams;

public User() {};

public User(String login, String firstName, String lastName,

String password, String teamname, String role) {

this.login = login;

this.firstName = firstName;

this.lastName = lastName;

this.password = password;

this.teamname = teamname;

this.role = role;

}

public User(String login, String password, String teamname, String role) {

this.login = login;

this.password = password;

this.teamname = teamname;

this.role = role;

}

public void setLogin(String login) {

this.login = login;

}

public String getLogin() {

return login;

}

public String getFirstName() {

return firstName;

}

public void setFirstName(String firstName) {

this.firstName = firstName;

}

public String getLastName() {

return lastName;

}

public void setLastName(String lastName) {

this.lastName = lastName;

}

public void setPassword(String password) {

this.password = password;

}

public String getPassword() {

return password;

}

public void setTeamname(String teamname) {

this.teamname = teamname;

}

public String getTeamname() {

return teamname;

}

public void setRole(String role) {

this.role = role;

}

public String getRole() {

return role;

}

public String toString() {

return firstName + " " + lastName;

}

public java.lang.String getAddress() {

return address;

}

public void setAddress(java.lang.String address) {

this.address = address;

}

public java.lang.String getCity() {

return city;

}

public void setCity(java.lang.String city) {

this.city = city;

}

public java.lang.String getDate() {

return date;

}

public void setDate(java.lang.String date) {

this.date = date;

}

public java.lang.String getEmail() {

return email;

}

public void setEmail(java.lang.String email) {

this.email = email;

}

public java.lang.String getProfession() {

return profession;

}

public void setProfession(java.lang.String profession) {

this.profession = profession;

}

public java.sql.Connection getConn() {

return conn;

}

public void setConn(java.sql.Connection conn) {

this.conn = conn;

}

public String AddNewUser() throws SQLException {

try{

DataSource dataSource=Singleton.getInstance().getDataSource();

Connection conn=dataSource.getConnection();

if (conn != null) {

PreparedStatement pst = null;

pst = conn.prepareStatement("INSERT INTO user(username,password,teamname,type,firstname,lastname,city,birthdate,address,profession,email) VALUES (?,?,?,?,?,?,?,?,?,?,?)");

pst.setString(1, login);

pst.setString(2, password);

pst.setString(3, teamname);

pst.setString(4, role);

pst.setString(5, firstName);

pst.setString(6, lastName);

pst.setString(7, city);

pst.setString(8, date);

pst.setString(9, address);

pst.setString(10, profession);

pst.setString(11, email);

pst.executeUpdate();

pst.close();

conn.close();

}

}

catch(Exception e){};

return "addedUsr";

}

public List<SelectItem> getTeams() throws SQLException{

return teamList();

}

public List<SelectItem> teamList() throws SQLException{

List<SelectItem> teams = null;

try {

teams = new ArrayList<SelectItem>();

DataSource dataSource=Singleton.getInstance().getDataSource();

teams = new ArrayList<SelectItem>();

Connection connection =dataSource.getConnection();

PreparedStatement ps = connection.prepareStatement("select * from researchteam order by teamname where teamname is not null");

ResultSet rst = ps.executeQuery();

while (rst.next()) {

String teamName = rst.getString("teamname");

teams.add(new SelectItem(teamName, teamName));

}

rst.close();

connection.close();

} catch(SQLException e_sql){

// log something

throw e_sql;

}

catch (Exception e)

{

// log something

}

return teams;

}

what have i to do now?

Can you help me modifing my code where it's needed?

Can you help me with code to create this scrollable list in my jsp page?

I haven't understood clearly what i have to do....

you're my only hope....please help me

giubata at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

I'm not sure what you are asking - but you already have the xml code defined:

<h:selectOneListbox value="#{user.teamname}">

<f:selectItems value="#{user.teams}"/>

</h:selectOneListbox>

you should get the list from the code you have written and the xml.

paroconsulta at 2007-7-14 18:28:19 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...