This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I am using MyFaces and I am getting an empty Dropdown with h:selectOneMenu. I have spent the whole day today trying to get this to work but with no success.... Please HELP!!!
I made sure I converted the department Id which is an int to a String for the SelectItem.
I have been reading/googling...some talk about Converters...Do I really need a converter? If so, why?
Please click on the My Profile link above to change your display name to match the JavaRanch Naming Policy of using your real first and real last names.
My question would be is how does JSF know what a SelectItem[] objects are and how to display them. That is what I believe is what a converter will give you, it will convert a SelectItem object into a String.
Or does JSF, by defualt, in these cases always call the toString() method.
/** Creates a new instance of ProjectsListItem */ public ProjectsListItem() { }
public ProjectsListItem(String myID, String myStr) { super(myID,myStr); }
public String getProjID() { return projID; } public String getProjName() { return projName; }
public void setProjID(String s) { projID = s; } public void setProjName(String s) { projName = s; }
}
Then in the managed bean
public synchronized java.util.ArrayList getProjectNames() throws SQLException, Exception { �get the data in a resultset � projectsList = new java.util.ArrayList(); while( rs.next() ) { Integer myInt = new Integer(rs.getInt("projectid")); // Store the projectid as a STRING - if you don't the decode() method // called to process the response from the browser will not know // how to convert the value and you'll throw a validation error ProjectsListItem myObject = new ProjectsListItem(new String(myInt.toString()),rs.getString("projectname").trim()); projectsList.add(myObject); } return projectsList;
Hope this helps...
Amy
madhuri madhuri
Ranch Hand
Joined: Jan 18, 2006
Posts: 58
posted
0
I do not find any mistake in the code. Just check and see if you are getting data from the DB or not.
for (int i=0; i <= valuesForDropDown.length; i++) { valuesForDropDown[i] = new SelectItem(new Integer(departments[i].getDepartmentId()).toString(), departments[i].getDepartmentName()); }
There is no need to convert departments[i].getDepartmentId() into String. I never converted it to String.
There is no need to convert departments[i].getDepartmentId() into String. I never converted it to String.
Usually the BeanUtils subsystem can handle String conversions automatically. It's when you want an off-standard conversion (such as Oracle Date string format to Date Object) that you have to worry about such things.
Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.