Win a copy of Terraform in Action this week in the Cloud forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

JSF managed bean question

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to create a dropdown list in my JSF page.

I have an object that contains 2 properties: accountTypeID and accountTypeDescr

I populate this object in my service tier layer using my DAO code and I use a transactionBean (managed bean) to bind to the JSF component.

In my managed bean the following method:



In my JSF I have:



I got the JSF component code from a previous post but my dropdown is not getting populated? Any help/direction would be appreciated.

Thank you.



 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Attribute value of <f:selectItems> tag only accept a list SelectItem, it does not accept List of an object.

Here is my solution for this:




Properties "id" and "name" of AccountType is just my example. Try it with your AccountType.

Hope this help you.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much for the reply. I am very new to JSF and obviously did not read clearly the documentation for SELECT ITEMS from the previous post.

I will try what you've stated below. Thank you again.

Ngoc Sinh wrote:Attribute value of <f:selectItems> tag only accept a list SelectItem, it does not accept List of an object.

Here is my solution for this:




Properties "id" and "name" of AccountType is just my example. Try it with your AccountType.

Hope this help you.

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the following error when I tried to use the code that Ngoc Sinh gave me above:

logServletError SRVE0293E: [Servlet Error]-[Faces Servlet]: org.apache.jasper.el.JspPropertyNotFoundException: /index.jsp(60,7) '#{transactionBean.acctTypes}' The class 'pagecode.TransactionBean' does not have the property 'acctTypes'.

I have an architectural question here. I have a DAO interface, DAO tier code, Service interface, Service tier code, Managed Bean code, and a BOM tier. My service interface is used by the managed bean code to call the code to populate the dropdown list AccountTypes. But I get the error above because I do not want the JSF code to call the code in the DAO level directly. The property of acctTypes sits in the DAO level. Do I have to define the acctTypes property in the service interface in order for JSF to see it or does it have to go into the managed bean?

Here is my managed bean transactionBean:



Any help/direction would be greatly appreciated. Thanks.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added the same property, List<SelectItem> accountTypes, that I already have in the transactionService helper class as indicated below:



But I am still getting this error:

#{transactionBean.accountTypes}' The class 'pagecode.TransactionBean' does not have the property 'accountTypes'

Any suggestions/direction would again be very much appreciated. I had found that in my original post I DID NOT have the property named correctly either which is now correct.

Thanks again.
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another person from another list server was able to help me by stating that in the managed bean to put in a proper getter method for the accountTypes in the JSF page and that fixed my problem.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic