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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Value conflict dropBox

 
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi all,

I have this JSF code:


And this Java one:



This line doesnt match well the required syntax.



What bean represents?

Any iadea, please?
     
 
Saloon Keeper
Posts: 28480
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
When you select a value from the dropdown list and submit the form, JSF will lookup the object named "bean" and do this or some equivalent:


The value will be the "value" atttribute of the SelectItem object (label/value) corresponding to the selected item.

This means that the method "getStatuses()" for the backing bean named "convert" must have either returned a collection (List or array) of SelectItem's OR that it returns something that JSF (version 2 or higher) can automatically convert into a collection of SelectItem's with a label and value for each SelectItem.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
As there is a fix number of items in the catalog, I am using an enumeration

 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I have modified the enum class:



In the .jsp


I am using Servlet for this:



When I run it, I get a white screen with this:


I have added the jar jstl1.2.jar

Any idea, please?

 
Tim Holloway
Saloon Keeper
Posts: 28480
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Don't even think about it.

Despite some questionable examples by Oracle, JSTL is a horrible fit for JSF. There's nothing in JSTL that JSF doesn't have a better version of in its native framework.

JSF has not been very good about handling enums, in my experience. What I recommend it that you build a SelectItem array with one SelectItem per enum value.

I believe you can do this in a generic way by invoking getEnumConstants on the enum class itself, which will return an array of Enum's. Then allocate a corresponding array of SelectItem and populate it by iterating the enum constants array, constructing a SelectItem from its integer value and display name, then adding that SelectItem to the SelectItem array you just built.

Note that this means that your setValue() method will have to accept an argument of type int, which you will then have to translate back into its corresponding enum (the enum having that ordinal value).
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Oki later on I will try with JSF now I switch into JSP. So I post this in JSP forum.
 
Angus Ferguson
Ranch Hand
Posts: 1402
3
Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Fixed. It was very silly, I was using an index.html instead if an index.jsp
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
    Bookmark Topic Watch Topic
  • New Topic