我在带有primefaces的jsf中使用datalist,我面临的问题是所选对象的支持bean类字段没有更新到datalist的选定行,它总是给出空对象。这是代码
查看文件 :
`<?xml version="1.0"?>`
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head />
<h:body>
<h:form>
<p:dataList value="#{tableBean.getList()}" var="job" id="cars"
paginator="true" rows="5" effectSpeed="fast"
paginatorTemplate="{PreviousPageLink} {CurrentPageReport} {NextPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5" type="none">
<f:facet name="header">
Applicants List
</f:facet>
<p:column>
<div style="width: 200px">
<h:outputText value="Name:" style="margin-left:10px" />
<h:outputText value="#{job.name}" style="margin-left:10px" />
<br />
<h:outputText value="Applied for:" style="margin-left:10px" />
<h:outputText value="#{job.jobtitle}" style="margin-left:10px" />
<br />
<h:outputText value="Degree:" style="margin-left:10px" />
<h:outputText value="#{job.degree}" style="margin-left:10px" />
<br />
<h:outputText value="Experience:" style="margin-left:10px" />
<h:outputText value="#{job.experience}" style="margin-left:10px" />
<br />
<h:outputText value="Contact:" style="margin-left:10px" />
<h:outputText value="#{job.contact}" style="margin-left:10px" />
<br />
<h:commandLink value="Call for Interview" style="margin-left:10px"></h:commandLink>
</div>
<br/>
<p:commandButton icon="ui-icon-search"
actionListener="#{tableBean.printView}" title="View Detail">
<f:setPropertyActionListener value="#{job}"
target="#{tableBean.selectedJob}" />
</p:commandButton>
<p:separator id="separator" />
</p:column>
</p:dataList>
</h:form>
</h:body>
</f:view>
表 bean 类:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import DAO.JobApplicationDao;
import DTO.JobApplicationDto;
@ManagedBean
@ViewScoped
public class TableBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
public JobApplicationDto selectedJob;
public TableBean() {
}
public List<JobApplicationDto> getList() {
List<JobApplicationDto> joblist = new ArrayList<JobApplicationDto>();
JobApplicationDao dao = new JobApplicationDao();
joblist =dao.getDroppedCv();
return joblist;
}
public JobApplicationDto getSelectedJob() {
return selectedJob;
}
public void setSelectedJob(JobApplicationDto selectedJob) {
this.selectedJob = selectedJob;
}
public void printView(ActionEvent event) {
try{
System.out.print("Selected Person "+getSelectedJob.getName());
}catch(Exception e){
}
}
}