• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsf selectitems problem  RSS feed

 
kartik rathore
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i am new to jsf. have been trying to develop a simple online application.

within the application i have a bean which accesses a class which retrieves a list of accounts from a database and send it to the bean in the form of list. the jsp page is used a view. i use the selectitem tag to display the list items . however when i display the list it shows the items in the form of [item1, item2].

however, when i hard code the individual index for the list then it displays it properly.

thus my problem is to diply the list items without hard coding them.

i cant figure out what is going wrong...

any help would be great.

thanks


 
Vaibhav Mittal
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide the relevant code.
 
kartik rathore
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
requested code is as follows ...

database class code :-



bean code :--



JSP page Code :



Hope you can help .

thanks in advance
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't send the item list straight to the View. Instead, you have to construct a SelectItem object for each element in your data list and return an array or ordered collection of SelectItems.

One of the reasons for this is that an HTML <option> actually can contain 2 values, the option value itself and the displayed value as seen in the UI. The SelectItem allows you to bind these 2 values together into a single option-generating object. Often the option value is something like the record key and the displayed value is some useful value in the record like a person's name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!