ページネーションでPrimeFaces<p:dataTable>
を使用しています。対応する行選択のプロパティで使用<h:selectBooleancheckbox>
します。Map
私が直面している問題は、値を選択して送信するときにNullPointerException
. 値は、特定の行についてのみチェックされます。JSF 2.0 と PrimeFaces 3.0 を使用しています。
私のページは:
<p:dataTable id="ngoPhotoTab" paginator="true" rows="10" value="# {photoApprovelBean.lstNgoPhotos}" var="ngoPhoto">
<p:column headerText="NgoName">
#{ngoPhoto.ngoName}
</p:column>
<p:column headerText="Select">
<h:selectBooleanCheckbox id="ngoSelect" layout="pageDirection" value="#{photoApprovelBean.checked[ngoPhoto.photo_id]}" />
</p:column>
<f:facet name="footer">
<p:commandButton onclick="deletePhoto();" value="Delete" />
</f:facet>
</p:dataTable>
バッキング Bean ロジック:
public class PhotoApprovelBean {
public String deleteActPhoto() {
List checkedItems = new ArrayList();
try {
for (Iterator<PhotoApprovelBean> itr = disAppPhotoList.iterator(); itr.hasNext();) {
PhotoApprovelBean item = (PhotoApprovelBean) itr.next();
if (checked.get(item.getPhotoId())) {
checkedItems.add(item.getPhotoId());
}
}
toDeletePhoto(checkedItems);
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
public Map<Long, Boolean> checked = new HashMap<Long, Boolean>();
public Map<Long, Boolean> getChecked() {
return checked;
}
}
NullPointerException
ラインで発生しますif (checked.get(item.getPhotoId()))
。TheMap
には、最初のページの値のみが入力されます。これはどのように発生し、どうすれば解決できますか?