• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to over come conversion error

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
<h:outputText 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
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

use

instead. I am too late but this might help somebody else in need.
reply
    Bookmark Topic Watch Topic
  • New Topic