我有以下数据表:
<p:dataTable id="persons" styleClass="hide-column-names personTable"
value="#{personListDisplayerBean.allPersonsModel}" var="person"
paginator="true" rows="25"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,25,50,100"
selection="#{personDetailsDisplayerBean.selectedPerson}"
filteredValue="#{personListDisplayerBean.filteredPersons}"
selectionMode="single" widgetVar="personTable">
...
...
<p:column styleClass="person-list-image-column">
<p:graphicImage styleClass="thumbnail"
value="#{personListDisplayerBean.getImageForPerson(person)}" />
</p:column>
...
...
</p:dataTable>
(缩短一点)
现在我的问题:方法getImageForPerson
被调用两次。这篇文章在这里解释了原因:
Display dynamic image from database with p:graphicImage and StreamedContent
第一次调用一切都很好,但第二次调用时我只收到一个null作为参数......
方法本身看起来像这样:
String fileName = person.getObjectGUID();
File f = new File(fileName + ".jpg");
FileInputStream inputStream;
try {
inputStream = new FileInputStream(f);
} catch (FileNotFoundException e) {
return new DefaultStreamedContent();
}
stream = new DefaultStreamedContent(inputStream,"image/jpg");
return stream;
为什么JSF第二次调用Method时会给我一个null作为参数?我能以某种方式克服这个问题吗?
提前致谢:)