Reputation: 933
I'm having some problems with JSF navigation and passing parameters; this is the scenario:
Three pages: artists, albums, tracks
For each page a bean: ArtistBean, AlbumBean, TrackBean (session scoped)
The artist page contains a list of artists, each artistname is a link and when clicking it you navigate to the album page which lists the albums by that artist. Similarly, when clicking an album, you navigate to the track page with a list of tracks for that album.
The links looks as follows:
Page artist: <h:commandLink action="#{albumBean.showAlbums(artist)}" value="#{artist.name}" />
Page album: <h:commandLink action="#{trackBean.showTracks(album)}" value="#{album.name}" />
The beans looks as follows:
AlbumBean: public String showAlbums(Artist artist){
[generate list of albums, fetched by page "albums" using getAlbumList()]
return "Albums";
}
public List<Album> getAlbumList(){
return albumList;
}
TrackBean: public String showTracks(Album album){
[generate list of tracks, fetched by page "tracks" using getTrackList()]
return "Tracks";
}
public List<Track> getTrackList(){
return trackList;
}
I'm not sure if this is an "OK" way to handle navigation; calling a backing bean for a page that has not yet bean displayed. I also get some weird behaviour, mainly that the links to show tracks only works if I click twice, whereas the links to show albums always work when just clicking once.
Thanks in advance!
Upvotes: 0
Views: 765
Reputation: 2003
I'm not sure if it is wrong what you are doing. But I find it complicated. A more straightforward solutions seems to me the following:
You have 3 beans and 3 pages. Obviously artist bean is called in artist page and so on.
Navigating between pages is done via links and you add a parameter. On Album bean, read the passed parameter and fill you list of albums on basis of that parameter (you could use name or an id as key value)
Same goes for track info.
That way you don't need to have the beans on session scope. Better to use view scope.
Upvotes: 1