permaculture playing cards*
The moose likes JSF and the fly likes how to over come conversion error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "how to over come conversion error" Watch "how to over come conversion error" New topic
Author

how to over come conversion error

prathibha shiju
Greenhorn

Joined: Jun 19, 2007
Posts: 17
hi
i want to read the selected item from from a selectonelistbox. the list entries are having values label and value fields.
so i put the getters and setters of label and value in a seperate bean class and the getter and setter of that class inside my main bean class that is userbean. nad i want to get the label value of what i selected from list. so i tried to read that as
<hutputText value="#{StoreNameBean.drinks.label}" />
but i am getting the error
(Conversion Error setting value '300' for 'null Converter'. )

can anyone tell me what might have went wrong?
since i am new to jsf ,not sure of the way that i am using to read the field.please correct me if i am wrong.



my faces-config.xml is
<faces-config>
<managed-bean>
<managed-bean-name>StoreNameBean</managed-bean-name>
<managed-bean-class>my.UserBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
<managed-bean-name>drinks</managed-bean-name>
<managed-bean-class>java.util.ArrayList</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>

<list-entries>
<value-class>javax.faces.model.SelectItem</value-class>
<value>#{drink0}</value>
<value>#{drink1}</value>

</list-entries>

</managed-bean>

<managed-bean>
<managed-bean-name>drink0</managed-bean-name>
<managed-bean-class>
javax.faces.model.SelectItem</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
<managed-property>
<property-name>label</property-name>

<value>pepsi</value>
</managed-property>
<managed-property>
<property-name>value</property-name>

<value>200</value>
</managed-property>
</managed-bean>

<managed-bean>
<managed-bean-name>drink1</managed-bean-name>
<managed-bean-class>
javax.faces.model.SelectItem</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
<managed-property>
<property-name>label</property-name>

<value>cola</value>
</managed-property>
<managed-property>
<property-name>value</property-name>
<value>300</value>
</managed-property>
</managed-bean>

<navigation-rule>
</navigation-rule>
</faces-config>



regards
prathibha
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
Your selected item should be mapped to a String (or a Array of Strings for selectMany). If you need to map it to a drinks object directly, then you must use a converter.

BTW the SelectItems, should n't it be an Array instead of ArrayList? Are the SelectItems displayed correctly in your front end component? Just curious.
[ February 06, 2008: Message edited by: A. Dusi ]
prathibha shiju
Greenhorn

Joined: Jun 19, 2007
Posts: 17
hi Dusi,
my front screen is getting populated with the values .

this is the code..
<h:selectOneListbox id="drinks" value="#{StoreNameBean.drinks}"
size="5">
<f:selectItems value="#{drinks}"/>

</h:selectOneListbox>

in the main bean if i declare drinks as string , then i can print the value of value property using "#{StoreNameBean.drinks}"

but i want to get all the properties.
please help me
regards
prathibha
A. Dusi
Ranch Hand

Joined: Sep 27, 2004
Posts: 114
Did you try with a converter? Converters convert Strings to objects and vice versa. Google for examples on converters.
Map value attribute of selectOneListBox to a String and use a converter to get the object.
[ February 07, 2008: Message edited by: A. Dusi ]
Dimitri Dean
Greenhorn

Joined: Oct 04, 2009
Posts: 1

use

instead. I am too late but this might help somebody else in need.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to over come conversion error
 
Similar Threads
Acegi Configuration
Obtaining an instance of a Managed Bean declared with Application Level Scope
selectManyListbox not setting value
Help. commandButton does not invoke Bean's method.
problem with SelectOneListbox