PhotoAlbum actionLister not called
www.supernovasoftware.com Dec 23, 2010 11:32 PMI have always used Richfaces in my production apps, and now I am working on a personal project. I am working on a photo album so I started with the Richfaces Photoalbum.
I made a few modifications, but I cannot get the actionListener to be called in one circumstance. Below are the modifications relevant to this problem.
I added a list of albums and and a list shelves to Model.java so that I could conditionally display more complex filtered lists. This works fine for images and this a list is already provided in the Model.java
I also modified the resetModel method by adding paramters for these lists. With the modifications the photo album still functions as normal except for when I try to use #{model.albums} inside a4j:repeat. I am trying to pass this to the albumList.xhtml template.
org.richfaces.photoalbum.manager.Model
private List<Album> albums;
public List<Album> getAlbums() { return albums; }
public void setAlbums(List<Album> albums) { this.albums = albums; }
private List<Shelf> shelfs;
public List<Shelf> getShelfs() { return shelfs; }
public void setShelfs(List<Shelf> shelfs) { this.shelfs = shelfs; }
public void resetModel(NavigationEnum mainArea,
User selectedUser,
Shelf selectedShelf,
Album selectedAlbum,
Image selectedImage,
List<Image> images,
List<Album> albums,
List<Shelf> shelfs)
{
this.setSelectedAlbum(selectedAlbum);
this.setSelectedImage(selectedImage);
this.setSelectedShelf(selectedShelf);
this.setSelectedUser(selectedUser);
this.setMainArea(mainArea);
this.shelfs=shelfs;
this.albums=albums;
this.images = images;
}
I also added the following method to Controller.java
org.richfaces.photoalbum.manage.Controllerr;
public void selectSharedAlbums()
{
model.resetModel(NavigationEnum.MODEL_ALBUMS, user, null, null, null, imageDAO.findShared(), albumDAO.findShared(), null);
}
Note that I am setting the album list in the model via albumDAO.findShared(). This image list is also set imageDAO.findShared(), but this is only for my debugging example that will be shown shortly. Normally I would set it to null;
I stripped down the albumList.xhtml to try to find the problem, but I have had no success. The only difference in the a4j:repeat lists show below is the value used in a4j:repeat. Below is a stripped down version the of albumList.xhtml template.
<h:outputText value="List loaded from model.images" /><br/>
<h:outputText value="The actionListener is called and shows a cast class exception as expected" /><br/>
<a4j:repeat id="modelImages"
value="#{model.images}"
var="modelImage">
<a4j:commandLink id="modelImageId"
value="#{modelImage.name}"
actionListener="#{controller.showAlbum(modelImage)}"
reRender="mainArea, treePanel"/>
<br/>
</a4j:repeat>
<br/><br/><br/>
<h:outputText value="List loaded from model.albums" /><br/>
<h:outputText value="The actionListener is not called" /><br/>
<a4j:repeat id="modelAlbums"
value="#{model.albums}"
var="modelAlbum">
<a4j:commandLink id="modelAlbumId"
value="#{modelAlbum.name}"
actionListener="#{controller.showAlbum(modelAlbum)}"
reRender="mainArea, treePanel"/>
<br/>
</a4j:repeat>
<br/><br/><br/>
<h:outputText value="List loaded from user.albums" /><br/>
<h:outputText value="The actionListener is called and page is displayed properly" /><br/>
<a4j:repeat id="userAlbums"
value="#{user.albums}"
var="userAlbum">
<a4j:commandLink id="userAlbumId"
value="#{userAlbum.name}"
actionListener="#{controller.showAlbum(userAlbum)}"
reRender="mainArea, treePanel"/>
<br/>
</a4j:repeat>
If I try to use a list of images a class cast exception is thrown as expected because controller.showAlbum expects an album. If I use user.albums there no problem. No matter what I do if I use model.albums I cannot get the actionListener to be called. This work in this way no matter if I have only one or all three lists on the page. The list is rendered correctly, but the actionListener is never called.
Here are a list of my ideas for the cause of the problem:
1. Difference in the way that the albums are loaded.
I use imageDAO.findShared()
public List<Album> findShared()
{
return entityManager.createQuery("from Album a where a.shared=true")
.getResultList();
}
user.getAlbums() uses
public List<Album> getAlbums()
{
final List<Album> albums = new ArrayList<Album>();
for (Shelf s : getShelves()) {
albums.addAll(s.getAlbums());
}
return albums;
}
2. Invalid markup as discussed in the link below, but this is a simple case and the other lists work even when this one is on the page.
http://community.jboss.org/message/555813
3. Something to do with Seam conversations that I am misuderstanding.
Adding immediate="true" does not help.
Adding ajaxSingle="true" calls actionListener, but the selected album is null.
I am getting no errors logged or other debug logged info that seems useful.
I have spent several hours on this and I would greatly appreciate any help on how to debug or solve this problem.