Discussions
Categories
- 196.7K All Categories
- 2.2K Data
- 235 Big Data Appliance
- 1.9K Data Science
- 449.9K Databases
- 221.6K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 549 MySQL Community Space
- 478 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 532 SQLcl
- 4K SQL Developer Data Modeler
- 186.9K SQL & PL/SQL
- 21.3K SQL Developer
- 295.4K Development
- 17 Developer Projects
- 138 Programming Languages
- 292.1K Development Tools
- 104 DevOps
- 3.1K QA/Testing
- 645.9K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 153 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 17 Java Essentials
- 158 Java 8 Questions
- 85.9K Java Programming
- 79 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.2K Java SE
- 13.8K Java Security
- 203 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 398 LiveLabs
- 37 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.6K Other Languages
- 2.3K Chinese
- 170 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 230 Portuguese
JSF Conversion error for h:selectManyListbox

843844
Member Posts: 40,416
There's an exception (*Conversion error occurred*) from JSF on <h:selectManyListbox> component for id availableUsers which is bound to myBean*.*roleId
Now myBean*.*roleId is of Long datatype and so is the usersList*.*SelectItem*.*value. So, would not be any datatype mismatch. Tried using a converter too with no luck.
If you have come across any such issue, please do let me know, thanks!
-----------------------------------------
Exception
-----------------------------------------
[email protected]]
[8/14/08 1:59:44:645 IST] 00000061 jsf E com.sun.faces.context.FacesContextImpl addMessage Adding Message[sourceId=emailmessage:*availableUsers* ,summary=*Conversion error occurred*.)
[8/14/08 1:59:44:661 IST] 00000061 jsf E com.sun.faces.context.FacesContextImpl addMessage Adding Message[sourceId=emailmessage:selectedUsers,summary=Conversion error occurred.)
-----------------------------------------
*
JSF
*
-----------------------------------------
<h:selectManyListbox id="*availableUsers* " value="#{myBean.roleId}" converter="javax.faces.Long"
binding="#{myBean.usersListBox}" size="5" style="width: 138px; height: 102px">
<f:selectItems id="usersItems" value="#{myBean.usersList}"
binding="#{myBean.usersListBoxSelectItems}" />
</h:selectManyListbox></td>
-----------------------------------------
*
CLASS
*
-----------------------------------------
*{code}*
*class MyBean*
*private Long roleId;*
*private List usersList;*
*{code}*
usersList is an arraylist of SelectItem where each SelectItem is composed of a Long value and a String label as per the convention.
Comments
-
The value of the h:selectMany* components must be bound with an array or a collection. Simply because you can select more than one value. If you want to select only one value, then use h:selectOne* component instead and keep the properties as is.
-
Thanks BaluC for responding.
Did you mean that in the following code, myBean.roleId has to be necessarily an arraylist too apart from the fact that myBean.availableUsersList is infact an ArrayList from where the selectitems would be populated?
<h:selectManyListbox id="availableUsers" value="#{myBean.roleId}" converter="javax.faces.Long" -
How would you collect multiple values otherwise? Make it a Long[] or List<Long> instead of Long.
-
I tried using a List<Long>, but getting another error now, any help would be greatly appreciated, thanks!
Error:
[8/15/08 0:11:32:692 IST] 0000007e jsf E com.sun.faces.context.FacesContextImpl addMessage Adding Message[sourceId=emailmessage:selectedUsers,summary=Validation Error: Value is not valid)
JSF Code:
h:selectManyListbox id="selectedUsers" binding="#{myBean.selectedUsersListBox}" value="#{myBean.recipientIdList}" size="5"
converter="#{myBean.recipientIdListConverter}" style="width: 138px; height: 102px">
<f:selectItems id="selectedUsersItem" value="#{myBean.recipientList}" binding="#{myBean.selectedUsersListBoxSelectItems}" />
</h:selectManyListbox>
backing Bean Code for class myBean:
{code}public List recipientList;
private ArrayList recipientIdList;
private HtmlSelectManyListbox selectedUsersListBox;
private UISelectItems selectedUsersListBoxSelectItems;
public Converter getRecipientIdListConverter() {
return new Converter() {
public Object getAsObject(FacesContext facesContext,
UIComponent component, String value)
throws ConverterException {
if (value == null)
return null;
for (Iterator i = recipientIdList.iterator(); i.hasNext();) {
Long item = (Long) i.next();
String val = String.valueOf(item);
if (val.equals(value)) {
return item;
}
}
return null;
}
public String getAsString(FacesContext facesContext,
UIComponent component, Object object)
throws ConverterException {
if (object instanceof SelectItem) {
return ((SelectItem) object).getValue().toString();
} else if (object instanceof Long) {
return String.valueOf(object);
} else {
return object.toString();
}
}
};
}{code} -
IceLander wrote:You need to make sure that the values of the selected items (the recipientIdList) are part of the values of the provided selectItems list (the recipientList).
Error:
[8/15/08 0:11:32:692 IST] 0000007e jsf E com.sun.faces.context.FacesContextImpl addMessage Adding Message[sourceId=emailmessage:selectedUsers,summary=Validation Error: Value is not valid)
JSF Code:
h:selectManyListbox id="selectedUsers" binding="#{myBean.selectedUsersListBox}" value="#{myBean.recipientIdList}" size="5"
converter="#{myBean.recipientIdListConverter}" style="width: 138px; height: 102px">
<f:selectItems id="selectedUsersItem" value="#{myBean.recipientList}" binding="#{myBean.selectedUsersListBoxSelectItems}" />
</h:selectManyListbox> -
So have another POJO composed of recipientIdList and recipientList?
-
No, I don't mean that. If you have a List<SelectItem> for the dropdown with the values Long 1, Long 2 and Long 3, then you should make sure that the List<Long> for the selected items is null or contains nothing else than Long 1, Long 2 and/or Long 3. If you have for example a Long 4 in it, which isn't available in the dropdown values, then you will get this validation error.
By the way, I did a closer look for the converter. And that logic really doesn't make any sense. You don't need to worry about SelectItem in the converter, but about its values. Leave it away. JSF has just built in converter for Long <--> String which will be invoked 'automagically'.
This discussion has been closed.