Saturday, March 5, 2011

Cascading Dropdown List from Bean

I'll demonstrate how to build a dropdown list where the values are coming from your manage bean. A good useCase for this scenario is when you can't use a BC driven LOVModel and pretty much rely on a manage bean to build your list. In my example, i'm relying on a webservice to return me the list of possible dropdown items which i'll need based on a submitted locationId. On top of it, i keep this list in a pageFlowScope map so that once I have already fetched it, i don't do a refetch especially when i'm asking for the same location's departments.

For my sample, I have a table that contains items (generic) with a location Id. The HR schema has a table of Departments that can be filtered based on this locationId.

So the final running app looks like this.



And yes the departments are filtered based on the locaitonId. So now for the code.

PageFragment

BackingBean

PageFlowBean

A question was raised about how to refresh the list incase there was any dynamic change, the answer to that is to decrease the scope of the bean which holds our map.

Note:
retrieveDepartmentListFromDatasource(locationId) calls a webService to return a list of available departments.

3 comments:

  1. where does SelecteItem define for
    private Map> _itemMapList = new HashMap>();

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. hi am having a problem when passing my cascading lov. my use case is i have created Lov based on this sample http://mjabr.wordpress.com/2011/04/01/cascade-list-of-values/ when i test is working fine but when i run it in my jsff page is not passing the selected paramemter.
    i have put the partial trigerr,how can i do the above sample using a bean,i can send you a code

    ReplyDelete