aspose file tools*
The moose likes JSF and the fly likes JSF managed bean question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF managed bean question" Watch "JSF managed bean question" New topic
Author

JSF managed bean question

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

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.



Ngoc Sinh
Greenhorn

Joined: Jul 29, 2010
Posts: 3
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

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jun 21, 2005
Posts: 386

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

Joined: Jun 21, 2005
Posts: 386

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF managed bean question
 
Similar Threads
Help - question on selectOneListbox and page reloads
2 - Questions regarding <h:selectOneListbox...>
Question on dynamic dropdown list
trying to populate hidden field on my JSF form using jQuery
iterate in jsf