迭代从JSF页面内的查询中获得的实体的ArrayList
我有一个托管bean作为我的视图,其中我有一个名为迭代从JSF页面内的查询中获得的实体的ArrayList,jsf,jsf-2,arraylist,foreach,entities,Jsf,Jsf 2,Arraylist,Foreach,Entities,我有一个托管bean作为我的视图,其中我有一个名为List getImages()的方法,在这里我查询数据库并获取该方法返回的实体列表。一切都很好 我的问题是,当我尝试使用JSF使用迭代这个列表时,我已经解决了它。引发异常是因为我在将列表分配给结果集后正在修改列表。如果我只是返回结果集,一切都很好。因此,为了实现我在getProfileImageList()中的预期目标,我根据的建议从原始列表创建了一个新的ArrayList,然后在返回它之前对其进行修改 public List<Profi
List getImages()
的方法,在这里我查询数据库并获取该方法返回的实体列表。一切都很好
我的问题是,当我尝试使用JSF使用
迭代这个列表时,我已经解决了它。引发异常是因为我在将列表分配给结果集后正在修改列表。如果我只是返回结果集,一切都很好。因此,为了实现我在getProfileImageList()中的预期目标,我根据的建议从原始列表创建了一个新的ArrayList,然后在返回它之前对其进行修改
public List<ProfileImage> getProfileImageList() {
profileImageList = new ArrayList(facade.findAllByProfileId(1L));
while (profileImageList.size() < 4) { // Add placeholders to bring the list size to 4
ProfileImage placeHolder = new ProfileImage();
placeHolder.setProfileId(1L);
profileImageList.add(placeHolder);
}
return profileImageList;
}
public List getProfileImageList(){
profileImageList=新的ArrayList(facade.findAllByProfileId(1L));
while(profileImageList.size()<4){//添加占位符以使列表大小变为4
ProfileImage占位符=新建ProfileImage();
占位符.setProfileId(1L);
profileImageList.add(占位符);
}
返回profileImageList;
}
您可以将原始帖子中提供的getImages
的方法体作为编辑发布吗。感谢您的帮助。似乎您可以通过删除集合来克服此错误。unmodifiableList
方法调用并返回profileImageList
。实际上,这是后来添加的,认为可以解决此问题。仅返回profileImageList
会导致相同的错误。您可以尝试以下操作:返回新的ArrayList(profileImageList)代码>
javax.el.ELException: Error reading 'profileImageList' on type com.goobang.view.ImageUploadView
viewId=/profile/create_profile.xhtml
location=/Users/xxxxxxxxx/Documents/NetBeansProjects/testmaven/target/testmaven-1.0-SNAPSHOT/profile/create_profile.xhtml
phaseId=RENDER_RESPONSE(6)
Caused by:
java.lang.UnsupportedOperationException - Result lists are read-only.
at org.apache.openjpa.lib.rop.AbstractResultList.readOnly(AbstractResultList.java:44)
/profile/create_profile.xhtml at line 16 and column 87 value="${imageUploadView.profileImageList}"
public List<ProfileImage> getProfileImageList() {
profileImageList = new ArrayList(facade.findAllByProfileId(1L));
while (profileImageList.size() < 4) { // Add placeholders to bring the list size to 4
ProfileImage placeHolder = new ProfileImage();
placeHolder.setProfileId(1L);
profileImageList.add(placeHolder);
}
return profileImageList;
}